C# Interop.Word Adding an Image from project resource folder

Posted by iamnobody on Stack Overflow See other posts from Stack Overflow or by iamnobody
Published on 2011-01-06T16:51:48Z Indexed on 2011/01/06 19:53 UTC
Read the original article Hit count: 213

Filed under:
|
|
|

Hi guys.

Having some image problem with Interop.Word and C#. I want to add an image in the header of the document that I am going to generate. I have this code working perfectly

section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddPicture(@"C:\Logo.jpg", ref x, ref x, ref x, ref x, ref x, ref x, ref x);

Problem is that I can't have "C:\Logo.jpg" in the code since after publishing the project, there would most probably be no Logo.jpg in the C folder of the user. The image is already in my project's resource folder. I've used Image.FromFile("Logo.jpg") before but .AddPicture requires a string and not an image.

Any ideas? Any help would be greatly appreciated.

Thanks!

-- edit --

Saw this over the net:

string anyPath = @"C:\logo.jpg";
Properties.Resources.logo.Save(anyPath);
section.Headers.[...].Shapes.AddPicture(anyPath, ...

but then I still get a generic error in GDI+ or ExternalException was unhandled.

© Stack Overflow or respective owner

Related posts about c#

Related posts about image