word instacnce is not opening document in it

Hi,

I am creating instance of word in asp.net by using following code

PublicWithEvents wrdAppAs Word.Application

wrdApp =New Word.Application

......

when code reaches to

' Add a new document.

wrdDoc = wrdApp.Documents.Open(Server.MapPath(strSrcFileName))

code halts. It is creating instance of word but then nothing happens please tell me is this an issue of rights or code? and what will be the approperiate approach to do this work

Sidi

[723 byte] By [Sidi] at [2008-1-10]
# 1

Hi Sidi,

In fact this is a VSTO forum, so your issue is off topic here. As to Office automation question, there is a more appropriate place for you to post: Office Automation News Group

http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.office.developer.automation&lang=en&cr=US

However, what do you mean by saying “code halts”? Does it throw any exception? Or just you cannot see the Word opening? If you just did not see the Word open, have you set the wrdApp.Visible to true? Like:

Code Snippet

Word.Application application = new Microsoft.Office.Interop.Word.Application();

application.Visible = true;

object file = @"C:\test.docx";

Word.Document doc = application.Documents.Open(ref file, 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, ref missing,

ref missing);

Thanks

Ji

JiZhou–MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 2

Thanks I will post this question in the metioned forum.

Well on the following line program just get hang for indefinite time

wrdDoc = wrdApp.Documents.Open(Server.MapPath(strSrcFileName))

Though program is creating instance of word (its visible in task manager) I have reinstall MS office too but no luck please help
Sidi at 2007-10-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 3

Hi,

I can think of a few possibilities. Since you aren't getting an exception, my guess is that either the hang is really happening in Server.MapPath, the server you are trying to communicate with isn't responding (and you aren't waiting long enough to get the timeout), or possibly you are getting a modal dialog of some sort that you don't see because Word isn't visible.

I would start by moving the Server.MapPath to its own line and verifying that it does return and that the path it returns is correct. If it seems to be, try launching word from the command line using that path; i.e. <Office location>\winword.exe <document>. If there is a problem with the server, this will fail. Finally, you can try adding an "Application.Visible=true" call prior to opening the document so you can see what Word is doing during the open call. You could also attach a debugger to Word, break and dump the stack. To get symbols, please refer to the following KB article: http://support.microsoft.com/kb/311503. This would be the definitive way to understand what is happening within Word.

Sincerely,

Geoff Darst

Microsoft VSTO Team

GeoffDarst-MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 4
Thanks for your reply. I have noticed that when I changed the path of the document it start working but after few attempts it started behaving same as old (application hangs up without throwing exception when I try to open the document). Then I again renamed the document it again start working. It seems that its a problem of word application I tried to attache debugger to word but I dont know after attaching debugger what next step should I follow Please reply
Sidi at 2007-10-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...
# 5

Once you attach a debugger to Word, you would want to break and view the callstack for each thread. That will tell you what Word is blocked on. For example, if you see a MessageBox call at the top of the stack, you'll know there is a modal dialog hanging around somewhere.

It seems very suspicious that changing the path works for a while but then stops working. That makes me think you have a problem with your system. It might be worthwhile would be to download FileMon and watch the IO requests as they happen. You can get FileMon here: http://www.microsoft.com/technet/sysinternals/FileAndDisk/Filemon.mspx.

Sincerely,

Geoff Darst

Microsoft VSTO Team

GeoffDarst-MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Tools for Office,Visual Studio Tools for Office...