このコードを使用して、データを Word テンプレートに送信し、クライアントに送信します。
protected void Button1_Click(object sender, EventArgs e)
{
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
string DocFilePath = "";
//string FilePath = System.Windows.Forms.Application.StartupPath;
object fileName = Server.MapPath(@"~\asset\wordtemplates\Estelam.dot");
DocFilePath = fileName.ToString();
FileInfo fi = new FileInfo(DocFilePath);
if (fi.Exists)
{
object readOnly = false;
object isVisible = true;
object LetterNo = "LetterNo";
object LetterDate = "LetterDate";
object Attachment = "Attachment";
object To = "To";
object From = "From";
object Fname = "Fname";
object Lname = "Lname";
object FatherName = "FatherName";
object IDNumber = "IDNumber";
object BirthDate = "BirthDate";
object BirthLocation = "BirthLocation";
object PersonelID = "PersonelID";
object MembershipDate = "MembershipDate";
object Membership = "Membership";
object Degree = "Degree";
object Level = "Level";
object Guild = "Guild";
object Janbazi = "Janbazi";
object Esarat = "Esarat";
object Education = "Education";
object Field = "Field";
object Education2 = "Education2";
object DocLocation = "DocLocation";
Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref isVisible, ref isVisible, ref missing, ref missing, ref missing);
//Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref fileName);
WordApp.ActiveDocument.FormFields.get_Item(ref LetterNo).Result = TextBox_LetterNo.Text;
このコードはローカルで適切に機能しますが、このサイトを公開してサーバーに配置すると、このエラーが発生します。
ドキュメントが開かれていないため、このコマンドは使用できません。説明: 現在の Web 要求の実行中に未処理の例外が発生しました。エラーの詳細とコード内のどこでエラーが発生したかについては、スタック トレースを確認してください。例外の詳細: System.Runtime.InteropServices.COMException: ドキュメントが開かれていないため、このコマンドは使用できません。
ソース エラー: 現在の Web 要求の実行中に未処理の例外が生成されました。例外の発生元と場所に関する情報は、以下の例外スタック トレースを使用して特定できます。
サーバーで開くことができないのはなぜですか?このエラーを解決するには?
私はWindows7、VS2010、SQLServer2008、office2010を使用しており、サーバーではWindows Server 2008、IIS7、office2010を使用しています。
サーバーでこのエラーが発生した場合、どうすればよいですか?