469,657 Members | 1,816 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,657 developers. It's quick & easy.

Get the path of a file hosted by an excel process in C#

3
Hi,
I have a method in C# which checks if any Excel process is running on my system. If it finds any process is there a way to get the directory path of the file running in that excel process through C# code ? For example Book1.xls is running on my machine,C# code identifies this process and i need to get the directory path where Book1.xls is stored. I need this code ASAP.

Thanks.
Dec 11 '08 #1
4 2617
nukefusion
221 Expert 100+
You could certainly get the filename using interop and the office type library if a single instance of Excel is open. You'd use Marshal.GetActiveObject to get the instance of excel and then call ActiveWorkbook.FullName on the instance to retrieve the workbook filename.

If there is more than one instance open you might have trouble getting hold of the exact instance you want in order to extract the file name. Quite a lot of those issues have been covered recently in another thread here: Can't get correct instance of Excel for paste
Dec 11 '08 #2
pavi14
3
In my case there might be more than one excel file open. So i am checking for each process in the multiple excel processes. Can i get the path of each file by having a FOR EACH Loop. If there is a way can you plz show me the sample code
Dec 11 '08 #3
nukefusion
221 Expert 100+
If you can get the path for each Excel instances active workbook then I'm afraid I don't know how to do it.
These problems have already been covered in the thread I posted the link for. It may be worthwhile reading that thread as it also includes code samples that may give you an idea of how to proceed.
Dec 11 '08 #4
pavi14
3
Thankyou so much for your help.

On the other hand is there any way in C# where i can find whether a file in a folder is already open? If the file is already open then on click of a button on windows form it should activate the already opened file. If the file is not open the button click should open the file from the specifiec folder. Is there a way to do this in C#.Net. Any sample code is highly appreciated.

Thanks.
Dec 11 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Anthony | last post: by
5 posts views Thread by Saradhi | last post: by
2 posts views Thread by UK | last post: by
3 posts views Thread by Oleg Ogurok | last post: by
3 posts views Thread by eugenet | last post: by
9 posts views Thread by JimmyKoolPantz | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.