我正在尝试打开 .docx 文件并使用 Interop.Word.Application 将其转换为 PDF。它作为控制台应用程序工作,但如果我在我的 Web 应用程序中使用它,它就不起作用。我试图查看文件夹的权限。我给了“网络服务”完全控制权,但我仍然得到未在 word.Documents.Open 中设置的对象引用。你能告诉我可能是什么问题吗?我被这个错误困住了。请告诉我。我感谢任何建议。谢谢。
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object oMissing = System.Reflection.Missing.Value;
word.Visible = false;
word.ScreenUpdating = false;
string fileName = @"c:\OUTPUT\test.docx");
Document doc = word.Documents.Open(filename, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Activate();
如果您仍在寻找答案,我刚刚为我的项目找到了它。
打开 DCOM 配置设置:
dcomcnfg.exe
Microsoft Word 97-2003 Documents
-> 属性选项卡
Identity
,从Launching User
更改为Interactive User
试试这个;它可能对你有帮助。
在里面新建一个“Desktop”目录
"C:\Windows\SysWOW6