Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Reading a text file with StreamReader

Reply
 
Old 10-15-2008   #1 (permalink)
km


 
 

Reading a text file with StreamReader

I have a tab delimited text file that I open in Excel.
While it is open in Excel I need to open and read it from my C# application.
I get an access error opening the file with StreamReader or File.Open
The error message says that another application has the file open (which of
course I already knew).

Notepad can open the file while it is open in Excel. Why can't the framework?

I've tried specifying the access as read-only, no luck.

Any suggestions would be appreciated.

My System SpecsSystem Spec
Old 10-15-2008   #2 (permalink)
sloan


 
 

Re: Reading a text file with StreamReader

You can try the OleDb

http://blogs.msdn.com/gzunino/archiv...02/206377.aspx

I have a very basic excel and txt reader here:
http://sholliday.spaces.live.com/Blo...842A!176.entry
(downloadable code)

Or google
OleDbReader Excel
or
OleDbReader txt


"km" <km@xxxxxx> wrote in message
news:0102F58D-C3A9-45BD-A738-14E2B8BC3BA6@xxxxxx
Quote:

>I have a tab delimited text file that I open in Excel.
> While it is open in Excel I need to open and read it from my C#
> application.
> I get an access error opening the file with StreamReader or File.Open
> The error message says that another application has the file open (which
> of
> course I already knew).
>
> Notepad can open the file while it is open in Excel. Why can't the
> framework?
>
> I've tried specifying the access as read-only, no luck.
>
> Any suggestions would be appreciated.

My System SpecsSystem Spec
Old 10-15-2008   #3 (permalink)
sloan


 
 

Re: Reading a text file with StreamReader

When I say "try", I mean, I have no idea if it'll work or not.

Excel is obviously putting a lock on the file.
Check the "Open As" options under Excel, if they exist.




"sloan" <sloan@xxxxxx> wrote in message
news:eefhPExLJHA.4772@xxxxxx
Quote:

> You can try the OleDb
>
> http://blogs.msdn.com/gzunino/archiv...02/206377.aspx
>
> I have a very basic excel and txt reader here:
> http://sholliday.spaces.live.com/Blo...842A!176.entry
> (downloadable code)
>
> Or google
> OleDbReader Excel
> or
> OleDbReader txt
>
>
> "km" <km@xxxxxx> wrote in message
> news:0102F58D-C3A9-45BD-A738-14E2B8BC3BA6@xxxxxx
Quote:

>>I have a tab delimited text file that I open in Excel.
>> While it is open in Excel I need to open and read it from my C#
>> application.
>> I get an access error opening the file with StreamReader or File.Open
>> The error message says that another application has the file open (which
>> of
>> course I already knew).
>>
>> Notepad can open the file while it is open in Excel. Why can't the
>> framework?
>>
>> I've tried specifying the access as read-only, no luck.
>>
>> Any suggestions would be appreciated.
>
>

My System SpecsSystem Spec
Old 10-16-2008   #4 (permalink)
Fred


 
 

Re: Reading a text file with StreamReader

in news:0102F58D-C3A9-45BD-A738-14E2B8BC3BA6@xxxxxx, km wrote :
Quote:

> I have a tab delimited text file that I open in Excel.
> While it is open in Excel I need to open and read it from my C#
> application. I get an access error opening the file with StreamReader
> or File.Open
Did you try to use a FileStream instead of a path in the StreamReader
constructor ?
Many options exist when creating a FileStream.
In this way I don't get your error.

--
Fred
foleide@xxxxxx

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Reading A Text File VB Script
Reading text file at a URL VB Script
Reading file names and Searching for text VB Script
Refresh on Reading more than one variable from a Text file VB Script
Reading text file and charting them via powergadget PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46