开发者

C# Opening Word document via Windows service

I've got a problem while opening Word 2007 (DOCX) document via Windows service (running by account with administrator privileges).

        object fileNameO = templateFilename;

        _application.Visible = visible;
        _application.DisplayAlerts = WdAlertLevel.wdAlertsNone;

        //opening document
        _document = _application.Documents.OpenNoRepairDialog(ref fileNameO,
                                              ref _missing,
                                              ref _truevalue,开发者_如何转开发
                                              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);
        //activating document
        _document.Activate();

_document in _document.Activate(); is null (System.NullReferenceException: Object reference not set to an instance of an object.)

I've tried to open by Open and OpenNoRepairDialog methods.

It's quite strange because when I try to running thread (service) in console application everything is working fine !

Pls help :)


Launch dcomcnfg.exe (Component Services)

Then Console Root->Component Services->Computers->My Computer->DCOM Config->Microsoft Word Document->Right Click(Properties)->Identity Tab

Then select interactive user instead of launching user. By setting this MSWordwill be executed with the rights of user that is currently logged on.


check your com+ application security to clarify whether your service running account have relavant permissions for Word


Type dcomcnfg in the command prompt and press Enter; find and select Microsoft Word Document in the Applications list, then press the Properties button; Note: If you have Windows 2003\2008 then type dcomcnfg in the command prompt, expand the Component Services group, expand the Computers group, expand the My Computer group, expand the DCOM Config group, find and select the Microsoft Word Document->right mouse click->Properties. click the Identity tab. Check the "This user" checkbox, press Browse and specify the Administrator account; enter and re-enter the Administrator password;

http://www.neevia.com/support/examples/cr/?get=ex002aspnet


I have tried all the above and nothing worked. Creating the following directory worked for me on Windows 10.

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

The System Profile requires a Desktop folder to open Office files (Word, Excel etc.)

Now I can run my C# application as a service using LocalSystem.

Have a look at Automating Office via Windows Service on Server 2008


Create the following directory: C:\Windows\SysWOW64\config\systemprofile\Desktop

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜