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

    Question System.IO.Stream ?

    How to convert string or StringBuilder to System.IO.Stream using C# ?
    pls guide

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: System.IO.Stream ?

    What are you trying to do exactly ?

    You can WRITE and READ from streams, not 'convert'.

    e.g.

    Code:
    string sHelloThere = "Hello there";
    
    System.IO.MemoryStream stream = new System.IO.MemoryStream();
    System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
    writer.Write(sHelloThere);
    writer.Close();
    Similarly to read from a stream you can do :

    Code:
    byte [] abData = // from wherever
    
    System.IO.MemoryStream stream = new System.IO.MemoryStream(abData);
    System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
    string sRead = reader.ReadString();
    reader.Close();
    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Mar 2004
    Posts
    92

    Re: System.IO.Stream ?

    Hello
    Thanks for reply.
    Well, I am trying to load a file in Rich text box using

    RichTextBox.LoadFile Method (Stream, RichTextBoxStreamType)

    but my data is in string format (I am generating an RTF file at runtime), thats why i want to convert it in to stream

    please guide

    regards

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