StreamWriter go to end of file?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: StreamWriter go to end of file?

Hybrid View

  1. #1
    Join Date
    Jun 2010
    Posts
    5

    StreamWriter go to end of file?

    Hello, when I use streamwriter, it writes the data, then puts the cursor to the top of the document, it tends to overwrite it I think? How do I make it go at the bottom so it prints the next lot below it?

    StreamWriter.EndOfStream(); doesn't work

  2. #2

    Re: StreamWriter go to end of file?

    you are being very vague, and what you are saying is not true. You probably need to post some code, so that we can see where you are going wrong.

  3. #3
    Join Date
    Jun 2010
    Posts
    5

    Re: StreamWriter go to end of file?

    Sorry, I am ignorant. I just started C# the other day.

    Code:
    static void Header1(_cnf cnf, string var1, string var2, string var3, StreamWriter logF)
    {
                    logF.WriteLine("------------------------------------------");
                    logF.WriteLine("Text: "+ var1);
                    logF.WriteLine("Text: "+ var2);
                    logF.WriteLine("Text: "+ var3);
                    // Need to go to the end of the file.
                    logF.Flush();
    }
    Does that help at all?

    - Tom

  4. #4
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,451

    Re: StreamWriter go to end of file?

    Helps a little. Actually you should probably look at the overloaded methods for creating your stream writer. There is an overload with a boolean parameter for appending to the file instead of overwriting.

    Code:
    System.IO.StreamWriter aa = new System.IO.StreamWriter("myfile.txt", true);

  5. #5

    Re: StreamWriter go to end of file?

    It still does not help me, or the previous poster. We need to see more code flow, if you are opening and closing the stream everytime you want to write, then you need to use the append flag. If you open the stream once and write everything, there is something else wrong.

  6. #6
    Join Date
    Jun 2010
    Posts
    5

    Re: StreamWriter go to end of file?

    sotoasty's post solved it for me, thanks

    thanks guys

  7. #7
    Join Date
    Nov 2013
    Posts
    1

    Re: StreamWriter go to end of file?

    @sotoasty ; Thank you very much bro, i didn't even know there is an overload with a Boolean , that [,true] parameter, made everything True, Thanks again.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,197

    Re: StreamWriter go to end of file?

    Quote Originally Posted by Zaki Al-Qudah View Post
    @sotoasty ; Thank you very much bro, i didn't even know there is an overload with a Boolean , that [,true] parameter, made everything True, Thanks again.
    Glad this old post helped, but no need to guess what is available or rely on a 3 year old thread. Instead take a look at what is available for the class you are interested in in Msdn.

    http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx

    The msdn documentation will show you the different constructors, properties and methods for a class. Often it will also show you sample code as well.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center