Is there a way of creating a interactive word document?

ASP.NET: What is the way to get the process id for Windows Word after creating a Word document using C#?

Akshay Kumar at Quora Visit the source

Was this solution helpful to you?

Other answers

Assuming you will be attempting to fetch the Id immediately after creating the Word document, this might work: System.Diagnostics.Process[] wordProcesses = System.Diagnostics.Process.GetProcessesByName("WinWord"); Int32 id = wordProcesses.Last().Id;

Adithya Parthasarathy

I'm curious why you're needing the ID. If it's to shut down Word after you're done with it, I think I have a solution. If what you're doing is anything like the way I used Excel from VB.Net in ASP.Net years ago, you're accessing Word through a managed library, which interfaces to COM. The first thing you need to do is null out all the variables that you can that you used to access the Word document. Then you need to tell Word to "exit" (and then null out any remaining variables that relate to accessing Word, if there are any), and then you need to explicitly run .Net's garbage collector. The reason for this is Word will refuse to exit until all COM objects that are used to access it have a reference count of zero. If even one Office COM object is active, Word will not exit. The .Net interface you're using ups that reference count while its objects are active in memory. Once the garbage collector runs, those objects will be cleared, and then Word will exit. From what I read at the time, explicitly running the garbage collector was "dangerous," because doing so halts your application until the garbage collector finishes, and it's possible the garbage collector may deadlock on some other memory references your application uses, and never return from the call. I tried it out, though, and never ran into that problem. If you don't run the GC directly, the objects will eventually be cleared by the GC's own timing, and Word would probably exit eventually, but if you use Word frequently in this application, that will probably get your application in trouble. So it's worth running the GC explicitly, IMO.

Mark Miller

It depends on how you created the Word document. If you launched the Windows Word process via the System.Diagnostics.Process class, then you can get the process ID via the Id property.

Mike Stall

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.