How to get file Information

  • Thread starter Thread starter John
  • Start date Start date
J

John

How do I get the name/path of the word file that is open
(active) if I'm writting my application in C#. A link or
sample code would be great.
 
Hi,

Is this file open inside your application? , Please provide more details.

Cheers,
 
John,

First, you will have to get the running instances of Word. Once you
have that, you will have to access the automation model (using the static
GetActiveObject method on the Marshal class or defining GetActiveObject
through P/Invoke) and then find out the path of the document.

However, this is not easy. To be sure, you should do the following:

- Query the running object table. This can be done by calling the
GetRunningObjectTable API call through P/Invoke, and then getting the
IRunningObjectTable interface (defined in your code for COM interop).

- Call the EnumRunning method on the IRunningObjectTable interface. This
will give you a pointer to an IEnumMoniker interface.

- Call the Next method on that interface to get the IMoniker interface (this
is defined for you in System.Runtime.InteropServices.UCOMIMoniker),
effectively enumerating through the interfaces on the running
object table.

- For each IMoniker interface that you get, call GetObject on the
IRunningObjectTable interface, passing the IMoniker interface in. It will
return an IUnknown pointer to you.

- Try and cast this to the appropriate interface in word (probably a
document interface of some kind). Once you have this, you can get the path
of the document.

Hope this helps.
 
Nope the file is not open inside the application. I just want to know,
how will i detect the path of the word file that is opened, outside of
my application. My application will run on the background...
 
Back
Top