How to download "RDL report files" from SQL Report server 2008 programatically - vb.net

How can I download the "RDL report files" from SQL Report Server 2008 programatically (vb.net).
I just need to download all reports and upload all back in one click event. Is this possible?

Several times, I have used a program called SSRSExtractor (open source). It is available on CodeProject.com http://www.codeproject.com/Articles/339744/SSRS-Downloading-RDL-Files

I also had some code before to download reports from ssrs server
public void SaveAdhocReportsToFile()
{
string inputPath = "Reports";
string outPutDir = "D:\\Reports\\";
ExportListItemToFiles("/" + inputPath, ".rdl", outPutDir, ItemType.Report);
}
private void ExportListItemToFiles(string inputPath, string fileExtension, string outPutFolder, string itemType)
{
try
{
Console.WriteLine("Exporting " + itemType + " from SSRS - folder " + inputPath + " to " + outPutFolder);
string outPutFile = string.Empty;
List<CatalogItem> items = ReportService.ListChildren(inputPath, false).Where(x => x.TypeName == itemType).ToList();
foreach (CatalogItem item in items)
{
byte[] rpt_def = null;
XmlDocument doc = new XmlDocument();
rpt_def = ReportService.GetItemDefinition(item.Path);
MemoryStream stream = new MemoryStream(rpt_def);
outPutFile = string.Format(#"{0}{1}" + fileExtension, outPutFolder, item.Name);
if (File.Exists(outPutFile))
File.Delete(outPutFile);
doc.Load(stream);
doc.Save(outPutFile);
}
}
catch (SoapException ex)
{
throw new Exception(ex.Message);
}
}
You can refer to ReportingService2010 Methods: https://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010_methods%28v=sql.120%29.aspx

Related

WebView2 Navigate

I got an old Windows Forms Tool that I wrote a few years ago, which is using WebBrowser. I want to change it to WebView2 so it's more compatible with new Browsers, as it won't work anymore if you have like Edge Browser installed.
Here is my original Code which works:
public void SubmitData(string link = "")
{
WebBrowser wb = new WebBrowser();
try
{
if(link != "")
{
wb.Navigate(link, "_Blank");
}
else
{
String postdata = "portfolio=" + ControlHelper.SerializeXMLString(pf);
System.Text.Encoding encod = System.Text.Encoding.UTF8;
byte[] bytVal = encod.GetBytes(postdata);
//navString = "http://lt.morningstar.com/4uzvsjb3c3/xray/default.aspx?" + HttpUtility.UrlEncode(bytVal);
wb.Navigate("http://lt.morningstar.com/4uzvsjb3c3/xray/default.aspx", "_Blank", bytVal, "Content-Type: application/x-www-form-urlencoded");
}
}
catch(Exception ex)
{
FileLogger.HandleError("Submit caused an error!", true, true, "Error (Main, SubmitData): " + ex.Message, GlobalData._TempPath, GlobalData._logfile);
}
finally
{
//use to close app and dispose
wb.Dispose();
}
}
This is the new one, on which I get an error: ("The object reference was not set to an object instance.")
WebView2 wb2 = new WebView2();
String postdata = "portfolio=" + ControlHelper.SerializeXMLString(pf);
System.Text.Encoding encod = System.Text.Encoding.UTF8;
byte[] bytVal = encod.GetBytes(postdata);
navString = "http://lt.morningstar.com/4uzvsjb3c3/xray/default.aspx?" + HttpUtility.UrlEncode(bytVal);
Uri uri = new Uri(navString);
wb2.CoreWebView2.Navigate(navString);
//wb2.Source = uri;
wb2.Show();
I haven't worked with this for quite a while, so I'm not sure what I'm doing wrong here.
I appreciate any help on this.

Index Out of Bound exception while rendering RDLC Reports in ASP.NET Core

My ASP.NET Core MVC project has several reports. To render the reports as PDF, I'm using AspNetCore.Reporting library.
This library works fine for a single report but due to some cache issues it throws an exception while generating another report. The solution I found on the internet was to run report generation as a new process but I don't know how to implement that.
I found the suggestion to use Tmds.ExecFunction to run report generation as a seperate process. But I dont know how to pass parameters to the function.
Here is my code:
string ReportName = "invoiceDine";
DataTable dt = new DataTable();
dt = GetInvoiceItems(invoiceFromDb.Id);
Dictionary<string, string> param = new Dictionary<string, string>();
param.Add("bParam", $"{invoiceFromDb.Id}");
param.Add("gParam", $"{salesOrderFromDb.Guests}");
param.Add("tParam", $"{invoiceFromDb.Table.Table}");
param.Add("dParam", $"{invoiceFromDb.Time}");
param.Add("totalP", $"{invoiceFromDb.SubTotal}");
param.Add("t1", $"{tax1}");
param.Add("t2", $"{tax2}");
param.Add("tA1", $"{tax1Amount}");
param.Add("tA2", $"{tax2Amount}");
param.Add("AT1", $"{totalAmountWithTax1}");
param.Add("AT2", $"{totalAmountWithTax2}");
param.Add("terminalParam", $"{terminalFromDb.Name}");
param.Add("addressParam", $"{t.Address}");
param.Add("serviceParam", "Service Charges of applicable on table of " + $"{personForServiceCharges}" + " & Above");
var result = reportService.GenerateReport(ReportName, param, "dsInvoiceDine", dt);
return File(result,"application/Pdf");
This is my version of the function:
``` public byte[] GenerateReport(string ReportName, Dictionary<string,string> Parameters,string DataSetName,DataTable DataSource )
{
string guID = Guid.NewGuid().ToString().Replace("-", "");
string fileDirPath = Assembly.GetExecutingAssembly().Location.Replace("POS_Website.dll", string.Empty);
string ReportfullPath = Path.Join(fileDirPath, "\\Reports");
string JsonfullPath = Path.Join(fileDirPath,"\\JsonFiles");
string rdlcFilePath = string.Format("{0}\\{1}.rdlc", ReportfullPath, ReportName);
string generatedFilePath = string.Format("{0}\\{1}.pdf", JsonfullPath, guID);
string jsonDataFilePath = string.Format("{0}\\{1}.json", JsonfullPath, guID);
File.WriteAllText(jsonDataFilePath, JsonConvert.SerializeObject(DataSource));
FunctionExecutor.Run((string[] args) =>
{
// 0 : Data file path - jsonDataFilePath
// 1 : Filename - generatedFilePath
// 2 : RDLCPath - rdlcFilePath
ReportResult result;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Encoding.GetEncoding("windows-1252");
LocalReport report = new LocalReport(args[2]);
DataTable dt = JsonConvert.DeserializeObject<DataTable>(File.ReadAllText(args[0]));
report.AddDataSource(args[3], dt);
result = report.Execute(RenderType.Pdf, 1,Parameters);
using (var fs = new FileStream(args[1], FileMode.Create, FileAccess.Write))
{
fs.Write(result.MainStream);
}
}, new string[] {jsonDataFilePath, generatedFilePath, rdlcFilePath, DataSetName });
var memory = new MemoryStream();
using (var stream = new FileStream(Path.Combine("", generatedFilePath), FileMode.Open))
{
stream.CopyTo(memory);
}
File.Delete(generatedFilePath);
File.Delete(jsonDataFilePath);
memory.Position = 0;
return memory.ToArray();
}
But it throws exception "Field marshaling is not supported by ExecFunction" on line:
var result = reportService.GenerateReport(ReportName, param, "dsInvoiceDine", dt);
No Need to run report generation as a seperate process. Just Dont Pass extension as 1
in:
var result = localReport.Execute(RenderType.Pdf, 1, param);
The Solution is:
int ext = (int)(DateTime.Now.Ticks >> 10);
var result = localReport.Execute(RenderType.Pdf, ext, param);

SubreportProcessingEventHandler is not firing even without parameters in the subreport

I'm trying to use the subreport component in my main report but does not fire the event SubreportProcessingEventHandler even without any parameter in the sub-report that can generate any errors.
public ActionResult MyReport(DateTime dateReport)
{
var root = Path.GetDirectoryName(this.Server.MapPath("~"));
if (string.IsNullOrEmpty(root))
{
return this.HttpNotFound();
}
var path = Path.Combine(root, "bin\\Reports\\MainReport.rdlc");
if (System.IO.File.Exists(path))
{
this.reportViewer.LocalReport.ReportPath = path;
}
else
{
return this.View("Index");
}
this.LoadData(dateReport);
var reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
var deviceInfo = "<DeviceInfo>" + " <OutputFormat>" + reportType + "</OutputFormat>"
+ " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>"
+ " <MarginTop>0.2in</MarginTop>" + " <MarginLeft>0.4in</MarginLeft>"
+ " <MarginRight>0.4in</MarginRight>" + " <MarginBottom>0.1in</MarginBottom>"
+ "</DeviceInfo>";
Warning[] warnings;
string[] streams;
var renderedBytes = this.reportViewer.LocalReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return this.File(renderedBytes, mimeType);
}
private void LoadData(DateTime dateReport)
{
........
this.reportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(this.MySubreportEventHandler);
this.reportViewer.LocalReport.DataSources.Add(new ReportDataSource("UserDataSet", users.DistinctBy(u => u.UserName)));
this.reportViewer.LocalReport.DataSources.Add(new ReportDataSource("EluateReportDataSet", radiopharmacyEluateReports));
this.reportViewer.LocalReport.DataSources.Add(new ReportDataSource("MarkingProtocolReportDataSet", radiopharmacyMarkingProtocolReports));
this.reportViewer.LocalReport.Refresh();
}
public void MySubreportEventHandler(object sender, SubreportProcessingEventArgs e)
{
.....
e.DataSources.Add(new ReportDataSource("RadiopharmaceuticalQualityControlDataSet", radiopharmacyReportQualityControls));
}
I have checked the output and this warning is raised:
Warning: Warnings occurred while executing the subreport ‘Subreport1’. (rsWarningExecutingSubreport)
After more detailed observation, i noticed that subreport really need an parameter that matches with a parameter passed by main report. Without any parameter the subreport just don't work.

How to test login page with multiple webpage(present in notepad) using selenium web driver Java?

I am testing like 100 url everything is working good. my problem is when the test starts it get web url from notepad then open the url here my process is to check the login or not in some case if the for example 10th url shows 404 error the test terminate here it cant process further urls. Any solution for this process...
my codes
public class File {
#Test(dataProvider="testdata")
public void sum(String url)
{
System.out.println(url);
}
#DataProvider
public Object[][] testdata(){
int count=20;
Object[][] obj = new Object[count][1];
for(int i=0;i<=count;i++)
{
String fileName = "E:\\ework\\Web\\bin\\Websearch\\test.txt";
try {
String line = null;
FileReader fileReader = new FileReader(fileName);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null)
{
String[] abs={line};
int size = abs.length;
for(int j=0;j<=size;j++)
{
obj[i][0]=abs[j];
}
}
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
}
`}
return obj;
}
}
thank you.:)
If you are using framework like TestNG then look at DataProviders for the same.
Use Try{} Catch(Exception e){} block. Insert your assertion in try block and once the assertion fails then try to capture the exception in some list or other data structure and after all urls are processed then iterate over the exception list and report it in your Reports or logs.

Save SSRS Report as pdf using Reporting Services

I've been trying to convert a SSRS Report to PDF and save to my local drive using the Reporting Web Services. Though I'm able to generate the corresponding pdf file but the contents of the file are missing. I've checked that the report I'm trying to convert is not an empty one. Only the header section is present there within the generated pdf files. Below is the code I'm using:
protected void GeneratePDFFromReport(object sender, EventArgs e)
{
RS2005.ReportingService2005 rs;
RE2005.ReportExecutionService rsExec;
// Create a new proxy to the web service
rs = new RS2005.ReportingService2005();
rsExec = new RE2005.ReportExecutionService();
// Authenticate to the Web service using Windows credentials
rs.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
rsExec.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
//rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://servername/reportserver/reportservice2005.asmx";
rsExec.Url = "http://servername/reportserver/reportexecution2005.asmx";
string historyID = null;
string deviceInfo = null;
string format = "PDF";
Byte[] results;
string encoding = String.Empty;
string mimeType = "application/pdf";
string extension = String.Empty;
RE2005.Warning[] warnings = null;
string[] streamIDs = null;
// Path of the Report - XLS, PDF etc.
string fileName = #"C:\Report\MemberReport.pdf";
// Name of the report - Please note this is not the RDL file.
string _reportName = #"/ReportFolder/ReportName";
string _historyID = null;
bool _forRendering = false;
RS2005.ParameterValue[] _values = null;
RS2005.DataSourceCredentials[] _credentials = null;
RS2005.ReportParameter[] _parameters = null;
try
{
_parameters = rs.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials);
RE2005.ExecutionInfo ei = rsExec.LoadReport(_reportName, historyID);
results = rsExec.Render(format, deviceInfo,
out extension, out encoding,
out mimeType, out warnings, out streamIDs);
try
{
FileStream stream = File.Create(fileName, results.Length);
stream.Write(results, 0, results.Length);
stream.Close();
}
catch { }
results = null;
}
catch (Exception ex)
{
throw ex;
}
}
Any help would highly be appreciated. Thanks.
Assuming that SSRS is working OK using browser, please modify your posted code as shown below:
1) Device info string, please set it as follows:
string deviceInfo = #"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; //Initial value was null
2) Create Header instance before using web call LoadReport:
ExecutionHeader execHeader = new ExecutionHeader();
RE2005.ExecutionHeaderValue = execHeader;