[英]iTextSharp System.IO.FileNotFoundException
我在下面的发行版中遇到System.IO.FileNotFoundException,但在调试时却没有得到。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using Microsoft.Office.Interop.Word;
using System.IO;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using iTextSharp.text.xml;
using Microsoft.VisualBasic;
namespace CountingTool
{
public partial class MainWindow : System.Windows.Window
{
private string SelectedFile;
public MainWindow()
{
InitializeComponent();
}
private void LoadFileButton_Click(object sender, System.EventArgs e)
{
OpenFileDialog LoadFileDialog = new OpenFileDialog();
LoadFileDialog.Title = "Select file";
LoadFileDialog.Filter = "PDF files|*.pdf";
LoadFileDialog.InitialDirectory = @"C:\";
if (LoadFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
try
{
SelectedFile = LoadFileDialog.FileName;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
private void CountEach()
{
string FullPdf = ExtractFullPdf();
...
}
private string ExtractFullPdf()
{
PdfReader sourceDocument = new PdfReader(SelectedFile);
StringBuilder text = new StringBuilder();
for (int i = 1; i <= sourceDocument.NumberOfPages; i++)
{
text.Append(PdfTextExtractor.GetTextFromPage(sourceDocument, i));
}
sourceDocument.Close();
return text.ToString();
}
}
似乎引起问题的行是PdfReader sourceDocument = new PdfReader(SelectedFile);
。
任何想法将不胜感激。
谢谢
这里的问题是itextsharp.dll
必须与生成的.exe位于同一目录中。
如果您完全确定所指定的路径正确(即使可能不太可能),那么我建议您使用以下任一方法:
Request.PhysicalApplicationPath(“在此处输入路径”);
Server.MapPath(“在此处输入路径”);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.