Hi
I have below code and i want File should get automatically get created in c:\Drive of User. It should not ask user to save file.
C#
SAPbobsCOM.CompanyService oCmpSrv;
SAPbobsCOM.ReportLayoutsService oReportLayoutService;
SAPbobsCOM.ReportLayoutPrintParams oPrintParam;
oCmpSrv = oCompany.GetCompanyService();
oReportLayoutService = (ReportLayoutsService)oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService);
oPrintParam = (ReportLayoutPrintParams)oReportLayoutService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportLayoutPrintParams);
oPrintParam.LayoutCode = "PM10014";
oPrintParam.DocEntry = 555;
oReportLayoutService.Print(oPrintParam);
Thanks

Amit MohantyRank #112 · 20K reputationPosted Feb 12, 2025, 3:05 AM EST
Check this:
SAPbobsCOM.CompanyService oCmpSrv; SAPbobsCOM.ReportLayoutsService oReportLayoutService; SAPbobsCOM.ReportLayoutExportParams oExportParam; oCmpSrv = oCompany.GetCompanyService(); oReportLayoutService = (SAPbobsCOM.ReportLayoutsService)oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService); oExportParam = (SAPbobsCOM.ReportLayoutExportParams)oReportLayoutService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportLayoutExportParams); if (!System.IO.Directory.Exists(@"C:\Drive")) { System.IO.Directory.CreateDirectory(@"C:\Drive"); } oExportParam.LayoutCode = "PM10014"; oExportParam.DocEntry = 555; oExportParam.ExportType = SAPbobsCOM.ReportExportType.ret_PDF; oExportParam.Path = @"C:\Drive\Report.pdf"; oReportLayoutService.Export(oExportParam);Ramco RamcoRank #462 · 5.4K reputationPosted Feb 12, 2025, 3:16 AM EST
Hi Amit
It is giving Error - ReportLayoutExportParams does not exist in namespace SAPbobsCOM
Thanks
Ajesh DalviRank #4,382 · 347 reputationPosted Feb 13, 2025, 3:35 AM EST
var pdfPath = Path.Combine(Server.MapPath(path_name)); var formFieldMap = PDFHelper.GetFormFieldNames(pdfPath); string username = "Test"; string password = "12345"; String file_name_pdf = "Test.pdf"; var pdfContents = PDFHelper.GeneratePDF(pdfPath, formFieldMap); WebRequest request = WebRequest.Create(Server.MapPath("~/PDF/" + pdfContents)); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential(username, password); Stream reqStream = request.GetRequestStream(); reqStream.Close();Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Feb 14, 2025, 5:50 AM EST
Hello Ramco,
To automatically save the file to a specific location (e.g.,
C:\Drive) without prompting the user, you need to modify your code to specify the output file path and ensure the file is saved directly to the desired location. Unfortunately, thePrintmethod in theReportLayoutsServicedoes not directly support saving to a file without user interaction. However, you can achieve this by using a workaround, such as printing to a PDF printer and saving the file programmatically.Below is an example of how you can achieve this using a PDF printer (e.g., Microsoft Print to PDF or a third-party PDF printer):
using SAPbobsCOM; using System; using System.Diagnostics; class Program { static void Main(string[] args) { // Initialize the company and services Company oCompany = new Company(); oCompany.Server = "your_server"; oCompany.CompanyDB = "your_company_db"; oCompany.DbUserName = "your_db_user"; oCompany.DbPassword = "your_db_password"; oCompany.UserName = "your_username"; oCompany.Password = "your_password"; oCompany.DbServerType = BoDataServerTypes.dst_MSSQL; // Adjust based on your DB type if (oCompany.Connect() != 0) { Console.WriteLine("Failed to connect to SAP Business One."); return; } // Get the company service and report layout service CompanyService oCmpSrv = oCompany.GetCompanyService(); ReportLayoutsService oReportLayoutService = (ReportLayoutsService)oCmpSrv.GetBusinessService(ServiceTypes.ReportLayoutsService); ReportLayoutPrintParams oPrintParam = (ReportLayoutPrintParams)oReportLayoutService.GetDataInterface(ReportLayoutsServiceDataInterfaces.rlsdiReportLayoutPrintParams); // Set the report layout and document entry oPrintParam.LayoutCode = "PM10014"; oPrintParam.DocEntry = 555; // Specify the output file path string outputFilePath = @"C:\Drive\Report.pdf"; // Set the printer name (use the name of your PDF printer) string pdfPrinterName = "Microsoft Print to PDF"; // Print the report to the PDF printer try { oPrintParam.PrinterName = pdfPrinterName; oPrintParam.OutputFile = outputFilePath; oReportLayoutService.Print(oPrintParam); Console.WriteLine("Report saved successfully to: " + outputFilePath); } catch (Exception ex) { Console.WriteLine("Error saving the report: " + ex.Message); } finally { // Disconnect from the company oCompany.Disconnect(); } } }Good Luck!
Sandhiya PriyaRank #26 · 43.2K reputationPosted Aug 12, 2025, 6:55 AM EDT
Answer: How to Save File in PDF Format in ASP.NET C#
In ASP.NET (C#), you can save or generate PDF files using libraries like iTextSharp, PDFSharp, or Syncfusion.
One of the most commonly used free libraries is iTextSharp.
1. Install iTextSharp
If using NuGet Package Manager:
2. Example: Create and Save a PDF
using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; public partial class GeneratePDF : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // File path to save the PDF string filePath = Server.MapPath("~/Files/MyDocument.pdf"); // Create Document object Document doc = new Document(PageSize.A4); PdfWriter.GetInstance(doc, new FileStream(filePath, FileMode.Create)); // Open document to write doc.Open(); // Add content to PDF doc.Add(new Paragraph("Hello, this is a sample PDF created in ASP.NET C#!")); doc.Add(new Paragraph("Date: " + DateTime.Now.ToString())); // Close document doc.Close(); Response.Write("PDF created successfully at: " + filePath); } }3. Saving PDF Directly to Browser (Download)
If you want the user to download it instead of saving on the server:
MemoryStream ms = new MemoryStream(); Document doc = new Document(PageSize.A4); PdfWriter.GetInstance(doc, ms); doc.Open(); doc.Add(new Paragraph("This PDF will be downloaded directly.")); doc.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Sample.pdf"); Response.BinaryWrite(ms.ToArray()); Response.End();Notes:
Always ensure you have write permissions on the folder if saving on the server.
For complex designs, use tables, images, and styles available in iTextSharp.
If working in .NET Core, use iText7 or QuestPDF instead.