prashant
prashant

Reputation: 361

how to detect MSword is opened with specific file?

I want to open word file from my Windows Application in C#. On button button click i called Process.start() with file name say "Test.doc". File name vary according to some situation.

Now as many times i click the button Process started with same file it started many instance of word.

i want it should open a single instance for same file, and if file name changes then only open new instance.

So how can i detect that word is opened with some file name?

Thanks

Upvotes: 1

Views: 169

Answers (1)

Shai UI
Shai UI

Reputation: 51918

Use a list that keeps tracks of Processes that are running. So:

List<Process> processes = new List<Process>();

When you click to open the file:
a) make sure the list does NOT contain a process with your filename. (traverse the list then look at process.Filename and compare it to the file you're wanting to open)
b) if it doesn't, add your process to the list and then just start the process.

Then use

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exited.aspx

To know if the process has exited. When it ends, get rid of it from your process list.

Upvotes: 1

Related Questions