Windows Vista Forums

Reading a text file with StreamReader
  1. #1


    km Guest

    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

  2. #2


    sloan Guest

    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

    >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

  3. #3


    sloan Guest

    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

    > 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

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

  4. #4


    Fred Guest

    Re: Reading a text file with StreamReader

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

    > 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

Reading a text file with StreamReader problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading A Text File vqthomf VB Script 2 19 Aug 2009
Reading text file at a URL Codeblack VB Script 7 09 Apr 2009
Reading file names and Searching for text Codeblack VB Script 11 22 Mar 2009
Refresh on Reading more than one variable from a Text file OldDog VB Script 4 11 Sep 2008
Reading text file and charting them via powergadget IT Staff PowerShell 2 19 Mar 2008