【发布时间】:2014-02-08 17:17:54
【问题描述】:
我在 .net 3.5 应用程序中使用 itextsharp 5.4.5。从文件路径创建 PdfReader 对象时,我收到文件未找到异常,但文件存在。我已经确认 File.Open 能够打开文件。测试代码:
try
{
FileStream f = File.Open(Server.MapPath("~/App_Data/pdf/EC_1.0.pdf"), FileMode.Open);
f.Close();
f.Dispose();
PdfReader pdfReader = new PdfReader(Server.MapPath("~/App_Data/pdf/EC_1.0.pdf"));
pdfReader.Close();
pdfReader.Dispose();
Response.Write("Succeed");
}
catch (IOException cex)
{
Response.Write("Fail: <br /><br /><b>Message:</b> " + cex.Message.Replace("<", "<").Replace(">", ">") +
"<br /><br /><b>Exception .ToString:</b> " + cex.ToString().Replace("<", "<").Replace(">", ">") +
"<br /><br /><b>Source:</b> " + cex.Source +
"<br /><br /><b>StackTrace:</b> " + cex.StackTrace +
"<br /><br /><b>TargetSite:</b> " + cex.TargetSite);
}
catch (Exception cex)
{
Response.Write("Fail: <br /><br /><b>Message:</b> " + cex.Message.Replace("<", "<").Replace(">", ">") +
"<br /><br /><b>Exception .ToString:</b> " + cex.ToString().Replace("<", "<").Replace(">", ">") +
"<br /><br /><b>Source:</b> " + cex.Source +
"<br /><br /><b>StackTrace:</b> " + cex.StackTrace +
"<br /><br /><b>TargetSite:</b> " + cex.TargetSite);
}
异常详情:
Message: C:\inetpub\wwwroot\HepBnet\research\DataSystem\App_Data\pdf\EC_1.0.pdf not found as file or resource.
Exception .ToString: System.IO.IOException: C:\inetpub\wwwroot\HepBnet\research\DataSystem\App_Data\pdf\EC_1.0.pdf not found as file or resource. at iTextSharp.text.io.RandomAccessSourceFactory.CreateByReadingToMemory(String filename) at iTextSharp.text.io.RandomAccessSourceFactory.CreateBestSource(String filename) at iTextSharp.text.pdf.PdfReader..ctor(String filename, Byte[] ownerPassword, Boolean partial) at iTextSharp.text.pdf.PdfReader..ctor(String filename) at ASP.errors_pdf_test_aspx.Page_Load()
Source: itextsharp
StackTrace: at iTextSharp.text.io.RandomAccessSourceFactory.CreateByReadingToMemory(String filename) at iTextSharp.text.io.RandomAccessSourceFactory.CreateBestSource(String filename) at iTextSharp.text.pdf.PdfReader..ctor(String filename, Byte[] ownerPassword, Boolean partial) at iTextSharp.text.pdf.PdfReader..ctor(String filename) at ASP.errors_pdf_test_aspx.Page_Load()
TargetSite: iTextSharp.text.io.IRandomAccessSource CreateByReadingToMemory(System.String)
我假设这是一个权限问题,但 itext 不应该使用与 .net 应用相同的用户吗?
【问题讨论】:
标签: c# asp.net pdf itextsharp