CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Location
    Israel
    Posts
    113

    Question Wite and Read to same file ERROR ?

    I'm using StreamWriter to write to file and at the same time I'm using the StreamReader to read from the same file.
    Doing that cause an exception when I'm trying to create the StreamReader when the file is already opened fro writing by the StreamWriter.

    How can I write and read at the same time to the same file?

    Thanks
    Sahron

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Wite and Read to same file ERROR ?

    You can use FileStream and FileAccess.ReadWrite access rights.

    Something like:
    Code:
    FileStream s = new FileStream(name, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
    Can read more in MSDN.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Sep 2004
    Location
    Israel
    Posts
    113

    Thumbs up Re: Wite and Read to same file ERROR ?

    Thanks,

    I changed my code as you sugested and it works OK.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured