Error reading word doc using Micorsoft.Office.Interop(Object library) via IIS 7

半腔热情 提交于 2019-11-26 17:25:34

问题


Iam facing issue while reading the document when runnning code from IIS. It is not reading the document and throwirng an error "No document is opne when trying to save the activedocument.".

 m_word.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 missing, ref missing, ref missing, ref missing, ref missing);


 m_word.ActiveDocument.SaveAs2(ref FileName_rtf, ref FileFormat, ref missing1, ref missing1,
                    ref missing1, ref missing1, ref missing1, ref missing1,
                    ref missing1, ref missing1, ref missing1,
                    ref missing1, ref missing1, ref missing1, ref missing1, ref missing1, ref missing1);

m_word.ActiveDocument is giving error when running from IIS. It is working in visual studio debugging mode.

I also tried the below code:

 Document doc_open =  m_word.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 missing, ref missing, ref missing, ref missing, ref missing);
            doc_open.Activate();

doc_open is retruning null and it throws object reference error in the second line. this works when code is in debugging mode. Error occurs when ran from IIS on development server where we have IIS 7 and MS offices too.


回答1:


Add: C:\Windows\SysWOW64\config\systemprofile\Desktop

It's incredibly successful.




回答2:


could be due to security setting, check this http://support.microsoft.com/kb/257757/en-us. Not a good idea to use interop on server, you may look at other option like openxml sdk




回答3:


Don't do this, it's not officially supported (highlighting by me):

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

Source: MS KB 257757. The article also contains a list of alternative solutions. If all else fails, you might have to resort to a third-party library that understands the Word format.



来源:https://stackoverflow.com/questions/8708653/error-reading-word-doc-using-micorsoft-office-interopobject-library-via-iis-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!