我在.net 3.5應用程序中使用itextsharp 5.4.5。當從文件路徑創建一個PdfReader對象時,我得到一個文件未找到的異常,但該文件存在。我已確認File.Open能夠打開文件。測試代碼:ItextSharp無法找到PDF
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應用程序?
我最初被這個答案困惑,因爲我從來沒有聽說過Unblock按鈕。只是爲了解決可能遇到此問題的任何其他人。您必須右鍵單擊itextsharp.dll文件並選擇「屬性」。從那裏您將看到「常規」選項卡底部的「解除阻止」按鈕。 –
我沒有開鎖按鈕。答案在這裏:http://stackoverflow.com/a/32394334/287516是我解決這個問題更簡單的方法。 – ilasno