Quantcast
Channel: Our ComponentOne » All Posts
Viewing all articles
Browse latest Browse all 14170

Reply To: RichTextBox (Save)

$
0
0

The C1RichTextBox is considered like a TextBox, like you can get and set the text and write to files yourself.

I’ve attached a sample that shows how to read and write to HTML/RTF files using C1RichTextBox.

Here is the key code to save a file:

private async void btnSave_Click(object sender, RoutedEventArgs e)
{
    FileSavePicker savePicker = new FileSavePicker();
    savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
    savePicker.FileTypeChoices.Add("HTML Page (*.html)", new List<string>() { ".html", ".htm" });
    savePicker.FileTypeChoices.Add("Rich Text Format (*.rtf)", new List<string>() { ".rtf" });
    savePicker.DefaultFileExtension = ".html";
    StorageFile file = await savePicker.PickSaveFileAsync();
    if (file != null)
    {
        if (file.FileType.Equals(".html") || file.FileType.Equals(".htm"))
        {
            // Save HTML
            await FileIO.WriteTextAsync(file, c1RichTextBox1.GetHtml(HtmlEncoding.StyleSheet));
        }
        else if (file.FileType.Equals(".rtf"))
        {
            // Save RTF
            await FileIO.WriteTextAsync(file, new RtfFilter().ConvertFromDocument(c1RichTextBox1.Document));
        }
    }
}

Viewing all articles
Browse latest Browse all 14170

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>