This is a migrated thread and some comments may be shown as answers.

Loading images from html that originates from exchange (email)

1 Answer 55 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
RICHARD FRIEND
Top achievements
Rank 2
RICHARD FRIEND asked on 05 Mar 2013, 02:03 PM
Hi

I am using the richtextbox to display email content (html) that i have downloaded from exchange via the exchange web api.

This fails to show images as the images are in the following format - is their anyway i can hook into the richtextbox and resolve these images (i can get them from exchange and save them to local disk or stream)



<img width="387" height="164" id="Picture_x0020_3" src="cid:image001.png@01CE15AF.A375F5C0">

1 Answer, 1 is accepted

Sort by
0
RICHARD FRIEND
Top achievements
Rank 2
answered on 05 Mar 2013, 02:32 PM
Never mind - i wrote this method to save and replace the email images with local ones, works well.


public string GetImageSafeMessageBody(EmailMessage message)
        {
            var ret = message.Body.Text;
             
            foreach (var att in message.Attachments.OfType<FileAttachment>())
            {
                if (!String.IsNullOrEmpty(att.ContentId) &&
                    att.ContentType.Contains("image", StringComparison.InvariantCultureIgnoreCase))
                {
                    var contentId = att.ContentId;
                    var imageType = att.ContentType.Replace("image/", String.Empty);
                    var tempFileName = String.Format("{0}.{1}", contentId, imageType);
                    var tempFile = Path.Combine(Path.GetTempPath(), tempFileName);
                    if (!File.Exists(tempFile))
                    {
                        att.Load(tempFile);
                    }
                    ret = ret.Replace(String.Concat("cid:", contentId), tempFile);
                }
            }
             
 
            return ret;
 
        }
Tags
RichTextBox
Asked by
RICHARD FRIEND
Top achievements
Rank 2
Answers by
RICHARD FRIEND
Top achievements
Rank 2
Share this question
or