Page 1 of 2
Export file to shared folder

Posted:
Thu Nov 11, 2021 7:17 pm
by Riyaz
Hi There
Is it possible to export a some documents such as Invoices, Purchase Orders, Some reports as PDFs to be saved under shared drives through a plugin.
Mean, map a selective shared drive in the plugin and save it there.
Re: Export file to shared folder 

Posted:
Fri Nov 12, 2021 9:31 am
by SBarnes
Below is the code out of the rest api that can create a pdf from a report that should be enough as a starting point
- Code: Select all
public ServiceStack.Web.IHttpResult Get(ReportsPDFGETRequest request)
{
JiwaApplication.Manager manager = this.SessionAs<JiwaAuthUserSession>().Manager;
JiwaApplication.Report.Configuration.ReportCollection m_Reports = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaApplication.Report.Configuration.ReportCollection>(null);
m_Reports.Read();
// find report with request.ReportID
JiwaApplication.Report.Configuration.Report report = m_Reports[request.ReportID];
if (report == null)
throw new JiwaApplication.Exceptions.RecordNotFoundException("Report not found");
JiwaApplication.JiwaPrintReport.JiwaPrintReport printReportObject = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaApplication.JiwaPrintReport.JiwaPrintReport>(null);
printReportObject.Setup();
printReportObject.LoadReport(report);
if (request.ReportParameters != null)
{
foreach (ReportParameter reportParameter in request.ReportParameters)
{
foreach (JiwaApplication.JiwaPrintReport.JiwaReportRange jiwaReportRange in printReportObject.JiwaReportRangeCollection)
{
if (printReportObject.JiwaPrintFormulaCollection[jiwaReportRange.FormulaKey].Name.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper() == reportParameter.Name.Replace("{", "").Replace("}", "").Replace("@", "").Trim().ToUpper())
{
jiwaReportRange.Value = reportParameter.Value;
break;
}
}
}
}
printReportObject.UpdateReport();
// export report to PDF
string tempFolderPath = System.IO.Path.GetTempPath();
string fileName = report.Title;
// Make filename safe
foreach (char c in System.IO.Path.GetInvalidFileNameChars())
{
fileName = fileName.Replace(c.ToString(), "");
}
string fullFileName = System.IO.Path.Combine(tempFolderPath, fileName) + ".pdf";
printReportObject.CrystalReportObject.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, fullFileName);
// Return the file
System.IO.FileInfo fileInfo = new System.IO.FileInfo(fullFileName);
return new HttpResult(fileInfo, asAttachment: request.AsAttachment);
}
Re: Export file to shared folder

Posted:
Sat Nov 13, 2021 7:41 pm
by Riyaz
Hi Stuart
Thanks for the same, prefer to do this via plugin, is that not possible?
Re: Export file to shared folder

Posted:
Sat Nov 13, 2021 7:49 pm
by Mike.Sheen
Riyaz wrote:Hi Stuart
Thanks for the same, prefer to do this via plugin, is that not possible?
Of course it is. Stuart's just provided the code from the REST API plugin that does what you need - you just need to grab the critical bits of code out of that.
Re: Export file to shared folder

Posted:
Sun Nov 14, 2021 8:03 am
by SBarnes
Thanks Mike, yes that was my intention.
Re: Export file to shared folder

Posted:
Mon Nov 15, 2021 11:23 am
by Riyaz
Thanks Mike & Stuart
Re: Export file to shared folder

Posted:
Mon Nov 15, 2021 10:59 pm
by Riyaz
Hi Mike and Stuart
Just further on this, it works fine for the reports but it wont if we try to save the sales order invoices, the printReportObject.LoadReport(report) wont accept it. It just throws the null error (Object reference not set)
Any suggestions pls
Re: Export file to shared folder

Posted:
Tue Nov 16, 2021 7:39 am
by SBarnes
Without seeing the actual code it is largely impossible to comment can you post a copy of the plugin in question?
Re: Export file to shared folder

Posted:
Tue Nov 16, 2021 2:04 pm
by Riyaz
Sorry thought had attached it, here it is
Re: Export file to shared folder

Posted:
Tue Nov 16, 2021 3:40 pm
by SBarnes
Trying to print a report in the save start in never going to work as you can't run a crystal report for data that isn't in the database i.e. Jiwa has not saved the data yet.
The first step would be to change the event you are attaching to.