473,416 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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

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

Similar topics

2
by: Garry Freemyer | last post by:
I wrote a screensaver, via Visual Studio 2003 in C# and I decided a wiser choice for me was to use an xml file to save my configs. Btw: I wonder if this is why every bit of documentation I've found...
2
by: Anthony | last post by:
Hi, I need to print word doc, excel, pdf, images(tiff), html. If this is impossible? Please suggest what i should do? - like handle each type in code separately? thanks
5
by: Saradhi | last post by:
How can I know whether a file in in use or it in C#?? For ex, if I have C:\\Documents and Settings\\upadrasta\\Local Settings\\Temp\\Palantir\\Daniel Johnston's Book Example--P50.xls I need...
2
by: UK | last post by:
I have developed a com interop dll to be used in excel. In the dll I need to read a file which exists in the same path as that of dll.How do I find the path of the dll. When I use...
0
by: Sathya | last post by:
Hi Am using an ASP.NET website. i have an excel template stored in a folder in the server. the excel template already has some data inside. i need to add some more data to the excel sheet...
3
by: Oleg Ogurok | last post by:
Hi all, I have a ASP.NET app that uses Excel interop to save an .xls file on disk in a temp folder and then read it back and e-mails it as an attachment. The problem is deciding where to store...
3
by: eugenet | last post by:
Hello, This is probably a newbie question. In my C# program, when I try to delete a file, I get an exception that the file is locked by another process. I would like to terminate the process...
9
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.