以下のリリースビルドでSystem.IO.FileNotFoundExceptionが発生しますが、デバッグ中は取得できません。iTextSharp 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);
です。
ご意見は大変ありがとうございます。 「(
Request.PhysicalApplicationPathここにパスを入力してください:あなたが指定したパスが、それはおそらく、私はどちらかあなたが使用することをお勧めすることができ、その後そうであっても正しいことを完全に確信している場合は
おかげ
リリース対テストビルドを実行するときに同じ環境内で実行可能ファイルを実行していますか? –
@MattSpinksうん、わたしです。/bin/Debugのビルドは正常に動作しますが、/ bin/Debug/app.publishのビルドには問題があります。 – stutch
私はちょうどtry catchブロックが、文字列中に何か問題を起こしていることを文字列割り当てに守っていることを指摘したいと思います。 –