将报告导出为PDF到服务器的临时文件夹

时间:2016-10-04 12:01:22

标签: c# asp.net pdf crystal-reports

我想将Crystal Report转换为PDF并将其存储在临时文件夹中供以后使用。该报告工作正常,只在尝试保存为PDF时遇到问题:

  

Could not find a part of the path 'C:\Program Files (x86)\IIS Express\~\temp\document.pdf'.

如何解决此问题?

ReportDocument doc;
TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
CrystalDecisions.CrystalReports.Engine.Database crDatabase;
CrystalDecisions.CrystalReports.Engine.Tables crTables;

doc = new ReportDocument();
doc.Load(fileName);
crConnectionInfo.ServerName = "localhost";
crConnectionInfo.DatabaseName = "Savings";
crConnectionInfo.UserID = "sa";
crConnectionInfo.Password = "P@ssw0rd";
crConnectionInfo.Type = ConnectionInfoType.SQL;
crConnectionInfo.IntegratedSecurity = false;
crDatabase = doc.Database;
crTables = crDatabase.Tables;

string rSql = "EXECUTE dbo." + strProcedureName + " @MemberId, @ItemId ";
SqlCommand cmd = new SqlCommand(rSql, conn);
cmd.Parameters.AddWithValue("@MemberId", txtMemberID.Text.Trim());
cmd.Parameters.AddWithValue("@ItemId", txtItemID.Text.Trim());

cmd.CommandType = CommandType.Text;
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataSet dataSet = new DataSet();
adpt.Fill(dataSet, "Savings");

foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
    crTableLogOnInfo = crTable.LogOnInfo;
    crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
    crTable.ApplyLogOnInfo(crTableLogOnInfo);
}
doc.SetDataSource(dataSet.Tables[0]);
CrystalReportViewer1.ReportSource = doc;
doc.ExportToDisk(ExportFormatType.PortableDocFormat, "~/temp/document.pdf");`

0 个答案:

没有答案