I am using the .Net libraries to generate reports as PDFs, which then get emailed. I am setting a query string and passing a parameter based on the Github examples.
My code works fine in VS 2019 but generates a fatal error on my AWS hosted web server. I believe the error is because of a progress modal generated by RDLViewer when using the rebuild() method or the saveas method(). Is there a way to suppress the progress modal?
The error message and my code are below.
thanks,
Morris
Error message:
System.InvalidOperationException
HResult=0x80131509
Message=Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
My Code:
using fyiReporting.RDL;
using fyiReporting.RdlViewer;
public static string CreateInvoicePDF(string invNum)
{
string drive = "C:";
int dashPosition = invNum.IndexOf("-");
string ldealer = invNum.Substring(0, dashPosition);
//string reportTemplateDir = "C:\\Anchor\\Connect\\Connect\\Connect\\Templates\\" + ldealer + "\\Report\\";
string reportTemplateDir = drive + "\\inetpub\\connect\\Templates\\" + ldealer + "\\Report\\";
string reportFileName = "basic_invoice2.rdl";
string reportFile = reportTemplateDir + reportFileName;
MyStatic.WriteLogMessage("Connect", "errorlog", reportFile);
//string invoiceDir = "C:\\Anchor\\Connect\\Connect\\Connect\\Statements\\" + ldealer + "\\";
string invoiceDir = drive + "\\ConnectData\\Statements\\" + ldealer + "\\";
string invoiceFileName = invNum + ".pdf";
string invoiceFile = invoiceDir + invoiceFileName;
MyStatic.WriteLogMessage("Connect", "errorlog", invoiceFile);
string logoFileName = GetDealerLogoFileName(ldealer);
//string logoDir = "C:\\Anchor\\Connect\\Connect\\Connect\\Images\\Logos\\";
string logoDir = drive + "\\inetpub\\connect\\Images\\Logos\\";
string logoFile;
string lstatus;
if (logoFileName == "Not Found")
{
logoFile = "";
}
else
{
logoFile = logoDir + logoFileName;
}
string querystring = "";
try
{
Uri sourcefile = new Uri(reportFile);
var reportSource = System.IO.File.ReadAllText(sourcefile.AbsolutePath);
querystring = "SELECT * FROM InvoiceWithDetail WHERE InvoiceNum = '" + invNum + "'";
RdlViewer rdlView = new RdlViewer();
rdlView.SourceFile = sourcefile;
rdlView.Report.DataSets["Data"].SetSource(querystring);
var paramstring = "logo=" + logoFile;
rdlView.Parameters = paramstring;
rdlView.Rebuild();
rdlView.SaveAs(invoiceFile, OutputPresentationType.PDF);
rdlView.Dispose();
lstatus = "success";
}
catch (Exception e)
{
lstatus = e.Message;
}
MyStatic.WriteLogMessage("Connect", "errorlog", lstatus);
return lstatus;
}