Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created the text editor in C# and wpf but which save the file only in rich text format..i want to save the file in .html format..
there is microsoft.mshtml.dll DLL to used..but i dont know how to used this and create such editor which open and save document in html format..please help me..
i am putting my code of rich text editor here..
please help me...
void CmdNew(object sender, RoutedEventArgs e)
       {
           txtcreatelssn.Document = new FlowDocument();
       }
       void Open1(object sender, RoutedEventArgs e)
       {
           System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog();
           openFile.Filter = "XAML Files (*.xaml)|*.xaml|RichText Files (*.rtf)|*.rtf|All Files (*.*)|*.*";

           if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           {
               // Create a TextRange around the entire document.
               TextRange documentTextRange = new TextRange(txtcreatelssn.Document.ContentStart, txtcreatelssn.Document.ContentEnd);

               using (FileStream fs = File.Open(openFile.FileName, FileMode.Open))
               {
                   if (System.IO.Path.GetExtension(openFile.FileName).ToLower() == ".rtf")
                   {
                       documentTextRange.Load(fs, System.Windows.DataFormats.Rtf);
                   }
                   else
                   {
                       documentTextRange.Load(fs, System.Windows.DataFormats.Xaml);
                   }
               }

           }
       }

       void save1(object sender, RoutedEventArgs e)
       {
           System.Windows.Forms.SaveFileDialog savefile = new System.Windows.Forms.SaveFileDialog();
           //System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog();
           savefile.Filter = "XAML Files (*.xaml)|*.xaml|RichText Files (*.rtf)|*.rtf|All Files (*.*)|*.*";

           if (savefile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           {
               // Create a TextRange around the entire document.
               TextRange documentTextRange = new TextRange(
                   txtcreatelssn.Document.ContentStart, txtcreatelssn.Document.ContentEnd);
               MemoryStream ms = new MemoryStream();
               // If this file exists, it's overwritten.
               using (FileStream fs = File.Create(savefile.FileName))
               {
                   if (System.IO.Path.GetExtension(savefile.FileName).ToLower() == ".rtf")
                   {
                       documentTextRange.Save(fs,System.Windows.DataFormats.Rtf);
                   }
                   else
                   {
                       documentTextRange.Save(fs, System.Windows.DataFormats.Xaml);

                   }
               }

           }

       }
Posted
Updated 13-May-11 20:52pm
v2

1 solution

You may want to have a read of this[^] blog post from Michael Sync which details how to work with a databound RichTextBox that supports XAML to HTML and HTML to XAML.

Basically, it works by converting the HTML (where it can) into XAML. Superficially HTML resembles XML, but it's not - the only real resemblance is that they both support tags and the <> characters. As HTML is not as strict in its well-formed nature as XML, it cannot be converted using XSL.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900