我正在.net 3.5应用程序中使用itextSharp5.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)我假设这是一个权限问题,但它不应该使用与.net应用程序相同的用户吗?
发布于 2014-02-08 18:52:09
我知道问题出在哪里了。出于某种原因,was服务器“阻塞”了itext库。右键单击库以访问属性,然后单击“Unblock”,然后强制一个应用程序重新启动,修复该问题。
我希望这能帮到别人..。
发布于 2015-11-07 07:09:05
我也有这个问题。结果被证明是相当复杂的,所以不确定其他人也会有同样的问题,但这是值得一查的。
在我的例子中,我的系统正在从存储在数据库中的文件名中打开PDF文件。当我移动我的文件时,我的系统不能再打开这些文件了,因为现在整个文件名太长了。例如:c:\the\path\here\in\total\was\just\way\too\long\anditbroke.pdf
还请确保检查Windows中的文件权限。应用程序的运行标识必须具有对文件的访问权限。
https://stackoverflow.com/questions/21649197
复制相似问题