By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,338 Members | 1,344 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,338 IT Pros & Developers. It's quick & easy.

How to get file Information

P: n/a
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.
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

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

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"John" <wi********@hotmail.com> wrote in message
news:07****************************@phx.gbl...
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.

Nov 13 '05 #2

P: n/a
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.

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"John" <wi********@hotmail.com> wrote in message
news:07****************************@phx.gbl...
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.

Nov 13 '05 #3

P: n/a

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...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.