出现“系统找不到指定的路径”之类的错误。在 .net 控制台应用程序中以 pdf 格式导出水晶报表时

问题描述 投票:0回答:1

我写了简单的导出水晶报表.rpt为pdf格式的代码,下面是参考代码。

// Create a Crystal Report document
ReportDocument reportDocument = new ReportDocument();

// Load the Crystal Report file
reportDocument.Load("Report.rpt");

// Set the database connection for the report
reportDocument.SetDatabaseLogon(username, password, server, database);

// Set the parameter value
reportDocument.SetParameterValue("cRef", 12);

// Export the report to PDF

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string pdfPath = Path.Combine(desktopPath, "Report.pdf");
reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, pdfPath);

//MemoryStream pdfStream = (MemoryStream)reportDocument.ExportToStream(ExportFormatType.PortableDocFormat);

// Save the memory stream to a PDF file

// File.WriteAllBytes(pdfPath, pdfStream.ToArray());


// Close and dispose of the database connection and report document
reportDocument.Close();
reportDocument.Dispose();

错误如下

System.Runtime.InteropServices.COMException (0x80004005):系统找不到指定的路径。 在 CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions,RequestContext pRequestContext) 在 CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) 在 CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) 在 CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext) 在 CrystalDecisions.CrystalReports.Engine.ReportDocument.Export(ExportOptions 选项)

我在多个设备上尝试了相同的代码,但对于一个设备我收到此错误。

所有设备 (Windows 10) 均具有 .net Framework 版本 4.7.2 和 SAP Crystal Reports 13.0 运行时(32 位)版本 13.0.12.1494

我收到错误的机器没有.net Framework版本4.7.2,所以我已经在机器上安装了它。

c# crystal-reports windows-10 console-application .net-4.7.2
1个回答
0
投票

如果目标路径是映射驱动器并且该计算机上的应用程序设置为以管理员身份运行,则它不会“看到”映射驱动器,除非您采取额外的步骤或除非您将映射驱动器路径更改为 UNC 路径。

如果这不是问题,请检查文件夹的权限。

© www.soinside.com 2019 - 2024. All rights reserved.