无法在C#窗口服务中打开MS Word文档 [英] Unable to open MS word document in window service in C#

查看:132
本文介绍了无法在C#窗口服务中打开MS Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

In my Window Service, I am opening MS Word document by the following line:

doc1 = WordApp.Documents.Open(UpFile, ReadOnly: true);
I am using:

using Word = Microsoft.Office.Interop.Word;
The same code works fine in Console Application but not working in Window Service. Any suggestions? I wan't my code to run at a specific time in a day so I am creating Window Service. Any other alternative?

(My code opens word documents and calculates line/word/character count/date last saved/last commented by) 





我尝试了什么:



我尝试用PHP编写相同代码,但我无法获取日期最后保存的内容和上次评论的人的姓名。



What I have tried:

I tried coding the same in PHP but I am unable to get date last saved and the name of the person who last commented.

推荐答案

您不应在服务器设置中使用Word interop。请参阅以下Microsoft文章:

http:// support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2 [ ^ ],

http://support.microsoft.com/kb/257757/en-us [ ^ ]。



最好不要在其他情况下使用它。合理的机会包括Microsoft Open XML SDK和NPOI( NPOI - Home [ ^ ])。请参阅本文中引用的过去的答案:如何从MS Visual中添加参考添加microsoft excel 15.0对象库Studio 2010 [ ^ ] 。



-SA
You should not use Word interop in the server setting. Please see these Microsoft articles:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^],
http://support.microsoft.com/kb/257757/en-us[^].

And it's also better not to use it on other situations. The reasonable opportunities include Microsoft Open XML SDK and NPOI (NPOI - Home[^]). Please see my past answers referenced in this one: How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010[^].

—SA


要在Windows服务上运行Interop库需要很多访问权限我猜,Windows服务应该在系统权限下运行,然后它应该访问你的word文档。

要授予访问权限,在以下文件夹中创建一个名为Desktop的文件夹

- 对于x64系统是必要的创建以下文件夹:

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

- 对于x86系统:

C:\ Windows \ System32 \ config \systemprofile \Desktop

(它看起来很有趣,但有效)

见下面的片段

热门Malva技术博客:如何在Windows 2008服务中使用Office 2007自动化 [ ^ ]







其他选择是创建一个控制台应用程序并使用柚木调度程序来运行您的控制台应用程序具体的时间。

我在控制台应用程序中使用了上述技术的互操作应用程序,它与Windows调度程序配合使用

(注意:用户创建Windows调度程序应该有行政权利)

希望有所帮助
To run Interop libraries on windows service needs much access permission I guess, windows services should running under system privilege and then it should access your word documents.
To give access create a folder named Desktop in following folders
- for x64 system is necessary to create the following folder:
C:\Windows\SysWOW64\config\systemprofile\Desktop
- for x86 system:
C:\Windows\System32\config\systemprofile\Desktop
(it looks a funny solution but works)
see below snippet
Hot Malva tech blog: How to use Office 2007 Automation in Windows 2008 service[^]

OR

Other alternative is to create a console application and use a teak scheduler to run your console application on specific time.
I have used above technique on interop application in console app and it works great with windows scheduler
(Note: the user used to create a windows scheduler should have administrative rights)
Hope it helps


这篇关于无法在C#窗口服务中打开MS Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆