Results 1 to 3 of 3

Thread: writing to MemoryStream

  1. #1
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Feb 2008
    Posts
    6
    Reputation
    0

    writing to MemoryStream

    I'm currently writing data to a memory stream using the following

    Code:
    Dim _ms As New MemoryStream
    Dim _tw As TextWriter = New StreamWriter(_ms)
    _tw.WriteLine("Line 1")
    _tw.Flush()
    _tw.WriteLine("Line 2")
    _tw.Flush()
    _tw.WriteLine("Line 3")
    _tw.Flush()
    _tw.Close
    The issue I have is that after Line 3 there is a blank line . I think I need to chance line 3 from _tw.WriteLine to something that does not put a line terminator on it

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,207
    Reputation
    2859
    StreamWriter Methods (System.IO)
    Write method. You should not call Flush, read the remarks for Close and Flush methods.
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  3. #3
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,994
    Reputation
    1727
    Quote Originally Posted by PeteN View Post
    I think I need to chance line 3 from _tw.WriteLine to something that does not put a line terminator on it
    You are quite correct. If you actually read the documentation for the StreamWriter class or even just pay attention to Intellisense as you type the code, you'll see exactly what that alternative is. You could probably even make a pretty good guess if you simply think about the name 'WriteLine'.

Similar Threads

  1. Question Saving a file from MemoryStream
    By gchq in forum ASP.NET General Discussion
    Replies: 1
    Last Post: 12-11-2010, 2:32 PM
  2. Streams, MemoryStream, StreamReader... questions
    By lordofduct in forum VB.NET General Discussion
    Replies: 0
    Last Post: 09-17-2010, 10:32 AM
  3. Resolved MemoryStream truncating input?
    By cbuhr in forum VB.NET General Discussion
    Replies: 3
    Last Post: 07-10-2009, 4:03 PM
  4. Cryptostream to bytes or memorystream
    By jwhite128 in forum Web Security
    Replies: 4
    Last Post: 05-28-2007, 11:02 PM
  5. Memorystream copy to two new memorystreams
    By cpopham in forum VB.NET General Discussion
    Replies: 0
    Last Post: 01-08-2006, 1:12 PM

Bookmarks

Posting Permissions

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