【发布时间】:2015-02-22 18:21:51
【问题描述】:
我正在使用 VS 2003 (Framework 1.1) 和 Crystal Reports for Visual Studio .NET 开发一个用 C# 开发的应用程序。 此应用程序制作发票并以 PDF 格式打印。
这样做也不例外,但是在开发环境中,文件在物理上是不存在的,我找不到。在生产环境中,工作没有问题:文件存在于指定路径中。
主要区别在于运行应用程序的机器。 开发机器是虚拟的 (Hyper-V 版本:6.2.9200.16384)在 Windows 8 Pro 上运行的 Windows XP SP3 2002 版本。开发是在虚拟机中完成的。 生产机器是 Windows XP SP3 2002。
我已经试过了:
- 更改机器中标识的用户。
- 将导出格式更改为 doc、xls,并且在两种环境中始终具有相同的结果。
- 更改记录文件的路径,避免使用“我的文档”。
- 谷歌搜索。
申请代码为:
// (Guarantee that all variables have the right type, are initialized and have a consistent value. txtDesde and txtHasta are textboxs)
string strFile = "myfile.pdf";
string strDirectory = @"myFolder\";
string strSubDirectory = @"MySubFolder\";
if (!System.IO.Directory.Exists(strDirectory))
{
System.IO.Directory.CreateDirectory(strDirectory);
}
strDirectory + = strSubDirectory;
if (!System.IO.Directory.Exists(strDirectory))
{
System.IO.Directory.CreateDirectory(strDirectory);
}
ReportClass a = new myCrystalReport(); // It is an existing Crystal Report and in an appropriate format
a.ResourceName = "myCrystalReport.rpt";
a.SetDataSource (myDataSet); //myDataSet is a System.Data.DataSet, loaded with the necessary and consistent data
DiskFileDestinationOptions dfdo = new DiskFileDestinationOptions();
dfdo.DiskFileName = strDirectory + strfile;
a.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
a.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
a.ExportOptions.DestinationOptions = dfdo;
//-> the next two lines have the same result
//a.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, strDirectory + strfile);
a.Export ();
a.Dispose ();
仅此而已,并且在两种情况下均无例外地运行。
正如我所说,唯一的问题是在我的开发环境中没有创建文件,而在生产机器中该文件没问题。
我从开发机器发布并安装de应用程序到生产机器。
由于应用程序在生产环境中工作,因此在业务中没有人如此关心。我特别感兴趣,因为我开发了。
当然,非常感谢。
【问题讨论】:
-
您是否尝试过单步执行代码..?您是否还检查以确定所有机器上的程序集版本或 dll 以及 .net 框架是否相同..?还有为什么不在该代码中添加一些错误检查和异常处理..?还将代码包装在 using(){} 周围,这样您就不必手动调用 a.Dispose()
-
@DJKRAZE 谢谢。我已经一步一步地运行代码,没有例外。程序集、dll 和框架版本都经过检查并且是正确的。这段代码包含在 try...catch 中。根据您的建议,我尝试了 using 块,但没有更改。
标签: c# .net pdf crystal-reports windows-xp-sp3