我正在尝试从外部程序生成pdf文件,然后使用Response运行它。在调试时,此代码在我的localhost上完美运行,但不会在客户端的服务器上生成该文件(Server 2008)。它从DOS命令成功在服务器上运行,但挂在aspx页面上。
String outputpath = Convert.ToString(Session["PDFOutputPath"]);
String output = outputpath + "barcode_reports.pdf";
System.IO.FileInfo myfile = new System.IO.FileInfo(output);
if (myfile.Exists)
{
System.IO.File.Delete(output);
}
String rpt = this.ReportButtonList.SelectedValue;
String _path = Convert.ToString(Session["ReportPath"]);
String parms = "'" + @outputpath + "','" + @rpt + "'";
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.WorkingDirectory = @_path;
p.StartInfo.FileName = "run_reports.exe";
p.StartInfo.Arguments = "barcode_reports " + @parms;
p.StartInfo.UseShellExecute = true;
p.Start();
p.WaitForExit();
System.IO.FileInfo myfile2 = new System.IO.FileInfo(output);
if (myfile2.Exists)
{
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile2.Name);
Response.AddHeader("Content-Length", myfile2.Length.ToString());
Response.ContentType = "application//pdf";
Response.TransmitFile(myfile2.FullName);
Response.End();
Response.Flush();
Response.Clear();
}
我知道进程启动是因为它触发了任务管理器进程,我知道输出文件夹是可访问的,因为初始擦除工作正常。有人能告诉我我错过了什么吗?