Although your inquiry was posted over three years, I came across it today. So I played around with my visual studio 2022 to find out possibilities.
You may be correct that it is not necessary to use third-party converters. You can do it all yourself using the DataFormat module the IDE provides.
Please, see the self-explanatory code snippet below. If it helps, please, mark it as answered.
Many regards.
Ola
/// <summary>
/// =====Written 10.08.2022=========
/// This 5 steps appraoch converts a richtextbox content to an html file
/// </summary>
/// <param name="The_richtextbox">the richtextbox</param>
/// <param name="the_full_path_filename">
/// the full path and name you want to call the file plu .html extension <para/>
/// For instance 1: "C:\\the_name_you_want.html" <para/>
/// For instance 2: "C:\\your_folder\\the_name_you_want.html" <para/>
/// </param>
private static void Convert_RTB_To_HTML(RichTextBox The_richtextbox, string the_full_path_filename)
{
try
{
//#1. hold a reference to the the_full_path_filename eg: "C:\\the_name_you_want.html"
string file_path = the_full_path_filename;
//#2. read the entire richttextbox content to range
TextRange range = new TextRange(The_richtextbox.Document.ContentStart, The_richtextbox.Document.ContentEnd);
//#3. Open the IO file stream to create the file. If it exists it will replace it
FileStream fStream = new FileStream(file_path, FileMode.Create);
//#4. Now save the file to the format you want to dataformat module
range.Save(fStream, DataFormats.Html); // use .Rtf preferably
//#5. Finally, close the stream
fStream.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// =====Written 10.08.2022=========
/// This 5 steps appraoch converts an html file to a richtextbox content
/// </summary>
/// <param name="The_richtextbox">the richtextbox</param>
/// <param name="the_full_path_filename">
/// the full path and name of the html file <para/>
/// For instance 1: "C:\\the_name_of_the_html_file.html" <para/>
/// For instance 2: "C:\\your_folder\\the_name_of_the_html_file.html" <para/>
/// </param>
private static void Convert_HTML_To_RTB(RichTextBox The_richtextbox, string the_full_path_filename)
{
try
{
//#1. hold a reference to the the_full_path_filename eg: "C:\\the_name_of_the_html_file.html"
string file_path = the_full_path_filename;
//#2. read the entire richttextbox content to range
TextRange range = new TextRange(The_richtextbox.Document.ContentStart, The_richtextbox.Document.ContentEnd);
//#3. Open the IO file stream to read the file.
FileStream fStream = new FileStream(file_path, FileMode.Create);
//#4. Now load the file to the range using the dataformat module. You can also try DataFormats.Xaml
range.Load(fStream, DataFormats.Html); //use .Rtf preferably
//#5. Finally, close the stream
fStream.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}