0

I am working on this Outlook VSTO Add-on, to add an image in the body of the email, but no luck at all for two weeks!!! It works with a normal path like c:\folder but it doesn't work if I want to use the Resources folder inside of the app.

When I run it and click on the button, it crashes and goes to the: document.Application.Selection.InlineShapes.AddPicture(ImagePath);

There is a Ribbon with a button. When user clicks, it should add the email signature in the body.

PLEASE HELP!!!!!!!!!!!!!!!!

        private void button_Click(object sender, RibbonControlEventArgs e) 
    {
        Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
        Word.Document document = inspector.WordEditor;

       string ImagePath = @"\Resources\Picture.jpg";


        if (document.Application.Selection == null)
        {
            MessageBox.Show("Please select the email body");
        }
        else
        {
            document.Application.Selection.InlineShapes.AddPicture(ImagePath);

        }
    }
Ivy Knm
  • 33
  • 7

1 Answers1

0

Word Object Model knows nothing about resources inside your assembly. It does not know and does not care about any external assemblies. It only understands files - you will need to extract the resource into a temp file and specify that file's fully qualified file name.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thanks for the reply! Any reference or similar project do you happen to know? – Ivy Knm Jul 16 '21 at 22:38
  • What are you having problems with? Saving a resource to a file? Creating a temporary file? See, for example, https://stackoverflow.com/questions/4405813/copying-embedded-resource-as-file-to-disk-in-c-sharp – Dmitry Streblechenko Jul 17 '21 at 00:26
  • All I want is to add an image to the body as signature. This image needs to be transferred to the user's computer via installation. The link you sent, is for saving the file to the project..But I want to load an image FROM the installation folder..this part is my main issue: string ImagePath = @"\Resources\Picture.jpg"; – Ivy Knm Jul 17 '21 at 20:38
  • So the problem is figuring out the fully qualified path to your assembly? See https://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in – Dmitry Streblechenko Jul 17 '21 at 21:25