Writing to file and Excel

R

RahimAsif

I am designing a data acquisition program that peridically collects
data from a panel and writes to a file. The way I am doing it right
now, every time I have data from the panel, I open the file, write my
data, and then close the file. The generated file itself is a text file
that is formatted either comma separated or tab separeted.

My problem is that the file my app generates can and probably will be
opened by the user in MS Excel. When MS Excel opens the file, it
somehow has exclusive access to it and when I try to open the file for
writing in my program, I get a file exception. I have tried keeping the
file open (instead of opening, writing and closing) during the duration
of the program but the result is the same.

My question is: Is there a way to open the file with my application so
that MS Excel cannot have exclusive access to it and opens it as read
only (sort of what happens when you try to open the same file with two
instances of MS Excel - the 2nd one would give you a message saying
that the file can only be opened as read-only because it is locked by
another user). That way, my application can continue logging data
regardless of what program the user opens the data file with. I have
tried messing around with FileShare enumeration but so far haven't had
much success.

Thanks in advance.
 
R

RahimAsif

Anybody with any idea on how to do this? Surprised not to find a single
response in about 24 hours.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top