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

    Save txt and img to one file using an rtf box

    I am trying to save a file that has an image pasted in along with the text that is typed. I have been able to get the text to save with no problem but the image pasted in is not saving.

    here is the code I am using:

    string path1 = cmbCat.Text;
    FileStream fs = new FileStream("\\BOS\\Cat\\" + path1 + "\\" + textBox1.Text + ".wri", FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);

    StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
    sw.Write(txtBox1.Text);
    sw.Flush();
    sw.Close();
    fs.Close();

    it saves the text just find but does not save the image. What can i do and how?

  2. #2
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Question Re: Save txt and img to one file using an rtf box

    Does *.wri format supports image ?
    Regards,
    MMH
    Rate my post if you find it usefull.

  3. #3
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Save txt and img to one file using an rtf box

    Of course it saves only the text. That's what a StreamWriter is for: to write text. Look at this:
    Code:
    sw.Write(txtBox1.Text);
    You're specifically writing the text. If you want to save an image then you have to save to a format that supports images. The RichTextBox is named as it is because is supports Rich Text Format. If you want to save all the formatting, images, etc. in the RichTextBox then you need to save the RTF code it contains. RTF code is somewhat like HTML code, and a RichTextBox is somewhat like a Web browser. It takes the code and renders it to a formatted output.

    I suggest that you read the MSDN documentation for the RichTextBox control so you understand how it works. In doing so you'll encounter its SaveFile and LoadFile methods, which allow you to save and load files in one line of code to either plain text or RTF format.
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

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