設定したASP.NETWebサイトで問題が発生し、デバッグが非常に困難です。
背景情報:
私のWebサイトには、ユーザーが1つまたは複数のMicrosoftWordドキュメントをアップロードできるページがあります。次に、ユーザーはボタンを押すことができ、コードはドキュメントを開き、単語を数え、テーブル内の単語数を返すことになっています。
これは、デバッガーを実行しているVisual Studioで完全に正常に機能しますが、別のコンピューターからWeb経由で実行しようとすると、エラーが発生します。
ここにいくつかのコードがあります。できるだけ単純化してみました。
// List of int's to hold the number of words in each document
List<int> words = new List<int>();
// Loop through the files that the user selected
// (The files have already been uploaded, and now their path is in "lstFileBox")
for (int i = 0; i < this.lstFileBox.Items.Count; i++)
{
try
{
String file = this.lstFileBox.Items[i].Text;
// MicrosoftWordOperations is a custom class
MicrosoftWordOperations wordOps = new MicrosoftWordOperations(file);
String contents = wordOps.GetContents();
int numWords = wordOps.CountWords(contents);
// Add number of words to my list
words.Add(numWords);
// Delete the uploaded file, which was stored in a temporary location
if (System.IO.File.Exists(file))
System.IO.File.Delete(file);
}
catch (Exception e)
{
}
}
// ...
// Then add number of words to a table
// ...
そして、MicrosoftWordOperations
コードはかなり基本的です:
public class MicrosoftWordOperations
{
private String _file;
public MicrosoftWordOperations(String file)
{
this._file = file;
}
public String GetContents()
{
object fileName = (object)this._file;
object missing = System.Reflection.Missing.Value;
Word.Application wordObject = new Word.Application();
Word.Document wordDocument = wordObject.Documents.Open(
ref fileName, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
Word.Document activeDocument = wordObject.ActiveDocument;
String fileContents = activeDocument.Content.Text;
wordDocument.Close(ref missing, ref missing, ref missing);
return fileContents;
}
public int CountWords(String text)
{
MatchCollection collection = Regex.Matches(text, @"[\S]+");
return collection.Count;
}
}
編集:
私はいくつかの基本的なデバッグを行うことができました、そしてこれが最初のコードブロックで捕らえられる例外です:
System.UnauthorizedAccessException:CLSID {000209FF-0000-0000-C000-000000000046}のコンポーネントのCOMクラスファクトリの取得が、次のエラーのために失敗しました:80070005アクセスが拒否されました。(HRESULTからの例外:0x80070005(E_ACCESSDENIED))。[path] \ MicrosoftWordOperations.cs:line 26のMicrosoftWordOperations.GetContents()で[path] \ WordCounter.aspx.cs:line69のContent_WordCounter.CountWords()で
編集:
MSWordがサーバーにインストールされています。
編集:
26行目:Word.Application wordObject = new Word.Application();
69行目:String contents = wordOps.GetContents();