Click here to Skip to main content
12,747,366 members (37,563 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# VSTO image
Hi guys.

I am creating a VSTO for outlook 2007.

What I am doing is I added a bunch of images to my resources folder of my application, I then loop through the folder and then get the images in the folder and for each image in that folder create a button and set that buttons background to the image.

I have a ribbon on the new email window, and when that is clicked a form with the above buttons with its background images comes up. What i want to happen now is on the buttons click event i need to insert the button that was clicked's background image to the new email.

I need the method to embed the image using the image object from the buttons background image and not using a string referencing an image from my hard disk.

Please advise on what to do, any help will be much appreciated.

Thanks in advance guys.

Here is my code for embedding the image in the email:

public void AddImage(MailItem mail, Image image)
if (!string.IsNullOrEmpty(mail.HTMLBody) && mail.HTMLBody.ToLower().Contains("</body>"))
                int mailBodyLength;
                if (mail.Body == null)
                    mailBodyLength = 0;
                    mailBodyLength = mail.Body.Length;
                //Get Image + Link
                Image imagePath = image;
                object linkAddress = "";

                const string SchemaPR_ATTACH_CONTENT_ID = @"";
                string contentID = Guid.NewGuid().ToString();

                //Attach image
                mail.Attachments.Add(imagePath, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, mailBodyLength, Type.Missing);
                mail.Attachments[mail.Attachments.Count].PropertyAccessor.SetProperties(SchemaPR_ATTACH_CONTENT_ID, contentID);

                //Create and add banner
                string banner = string.Format(@"<br/><a href=""{0}"" ><img src=""cid:{1}"" ></a></body>", linkAddress, contentID);
                mail.HTMLBody = mail.HTMLBody.Replace("</body>", banner);


But using this method throws an exception at this line:
mail.Attachments.Add(imagePath, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, mailBodyLength, Type.Missing);

the exception that gets thrown is :
Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
Posted 7-Feb-12 0:52am
Updated 7-Feb-12 22:56pm
B Birajdar 7-Feb-12 9:25am
Please post your code so that we can save time in guessing what exactly you want to achieve.
Member 8102934 8-Feb-12 3:57am
I have edited my question to add my code.
Member 8102934 8-Feb-12 3:57am
I have edited my question to add my code.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to use the LinkedResource class in .NET

Check the complete implementation here[^]

Do not forget to vote my solution.
Member 8102934 7-Feb-12 6:54am
Thanks for the response, but that is not what i am looking for. This part over here passes a path of the image: LinkedResource LinkedImage = new LinkedResource(@"J:\My Documents\Advika1.jpg"); I need to pass the image object to accomplish what i need to do.

for example:

Image i = Resources.Jellyfish;
LinkedResource LinkedImage = new LinkedResource(i);
Member 8102934 8-Feb-12 3:57am
I have edited my question to add my code.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 8 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100