public override List<CatalogItem> GetItems(string folderName, ItemTypeEnum type)
{
List<CatalogItem> _items = new List<CatalogItem>();
string targetFolder = HttpContext.Current.Server.MapPath("~/") +@"App_Data\ReportServer\";
if (type == ItemTypeEnum.Folder || type == ItemTypeEnum.Report)
{
targetFolder = targetFolder + @"Report\";
if (!(string.IsNullOrEmpty(folderName) || folderName.Trim() == "/"))
{
targetFolder = targetFolder + folderName;
}
}
if (type == ItemTypeEnum.DataSet)
{
foreach (var file in Directory.GetFiles(targetFolder + "DataSet"))
{
CatalogItem catalogItem = new CatalogItem();
catalogItem.Name = Path.GetFileNameWithoutExtension(file);
catalogItem.Type = ItemTypeEnum.DataSet;
catalogItem.Id = Regex.Replace(catalogItem.Name, @"[^0-9a-zA-Z]+", "_");
_items.Add(catalogItem);
}
}
else if (type == ItemTypeEnum.DataSource)
{
foreach (var file in Directory.GetFiles(targetFolder + "DataSource"))
{
CatalogItem catalogItem = new CatalogItem();
catalogItem.Name = Path.GetFileNameWithoutExtension(file);
catalogItem.Type = ItemTypeEnum.DataSource;
catalogItem.Id = Regex.Replace(catalogItem.Name, @"[^0-9a-zA-Z]+", "_");
_items.Add(catalogItem);
}
}
else if (type == ItemTypeEnum.Folder)
{
foreach (var file in Directory.GetDirectories(targetFolder))
{
CatalogItem catalogItem = new CatalogItem();
catalogItem.Name = Path.GetFileNameWithoutExtension(file);
catalogItem.Type = ItemTypeEnum.Folder;
catalogItem.Id = Regex.Replace(catalogItem.Name, @"[^0-9a-zA-Z]+", "_");
_items.Add(catalogItem);
}
}
else if (type == ItemTypeEnum.Report)
{
foreach (var file in Directory.GetFiles(targetFolder, "*.rdl"))
{
CatalogItem catalogItem = new CatalogItem();
catalogItem.Name = Path.GetFileNameWithoutExtension(file);
catalogItem.Type = ItemTypeEnum.Report;
catalogItem.Id = Regex.Replace(catalogItem.Name, @"[^0-9a-zA-Z]+", "_");
_items.Add(catalogItem);
}
}
return _items;
} |
public class ReportApiController : ApiController, IReportController
{
public object PostReportAction(Dictionary<string, object> jsonResult)
{
return ReportHelper.ProcessReport(jsonResult, this);
}
[System.Web.Http.ActionName("GetResource")]
[AcceptVerbs("GET")]
public object GetResource(string key, string resourcetype, bool isPrint)
{
return ReportHelper.GetResource(key, resourcetype, isPrint);
}
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("~/App_Data/GroupingAgg.rdl"), FileMode.Open, FileAccess.Read);
reportOption.ReportModel.Stream = fs;
}
public void OnReportLoaded(ReportViewerOptions reportOption)
{
}
} |
Hi Megha,Yes, we can achieve your requirement of passing as FileStream to ReportViewer instead of ReportPath. Please find the snippet handled in controller side below,
public class ReportApiController : ApiController, IReportController{public object PostReportAction(Dictionary<string, object> jsonResult){return ReportHelper.ProcessReport(jsonResult, this);}[System.Web.Http.ActionName("GetResource")][AcceptVerbs("GET")]public object GetResource(string key, string resourcetype, bool isPrint){return ReportHelper.GetResource(key, resourcetype, isPrint);}public void OnInitReportOptions(ReportViewerOptions reportOption){FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("~/App_Data/GroupingAgg.rdl"), FileMode.Open, FileAccess.Read);reportOption.ReportModel.Stream = fs;}public void OnReportLoaded(ReportViewerOptions reportOption){}}Please find the sample reference below which will assist your requirement,Note: In the above sample, we have read the physical path file as stream and loaded it. You can modify the sample as per your needs to pass the xml content as FileStream.Regards,Mageshyadav.M