Using custom cookies to get images to be shown inside HTML document in RadRichTextBox

1 Answer 27 Views
RichTextBox
MOGRO
Top achievements
Rank 1
MOGRO asked on 20 May 2021, 08:02 AM | edited on 20 May 2021, 08:25 AM

I use WPF RadRichTextBox to show/edit HTML-document containing images having restricted access. To show HTML-document inside RadRichTextBox I use HtmlFormatProvider.
In the case of using WebBrowser control, it is enough to call InternetSetCookie to pass user token to the WebRequest used there.

How can I pass the user token to the HTTP request used inside RadRichTextBox to get an image?

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 21 May 2021, 10:47 AM

Hello Morten,

I believe that the LoadImageFromUrl event is suitable for this case. Here is an example that shows how you can set the image (in your case you should download the image manully and set the data):

public MainWindow()
{
    InitializeComponent();
 
    HtmlFormatProvider provider = new HtmlFormatProvider();
    provider.ImportSettings.LoadImageFromUrl += ImportSettings_LoadImageFromUrl;
    provider.Import(File.ReadAllText(@"..\..\test.html"));
}

private void ImportSettings_LoadImageFromUrl(object sender, LoadImageEventArgs e)
{
    e.Handled = true;
    using (FileStream source = File.Open(@"..\..\test.png", FileMode.Open))
    {
        e.ImageElement.Init(source, "png");
    }

}

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
RichTextBox
Asked by
MOGRO
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or