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?
— 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.
Cant you use…
Use the relative location of the image file in the bin folder instead of an absolute positioned file
EDIT
You could use this to generate an absolute file location based on a relative link.
Relies on using WinForms
I don’t think your updated method will work too great on vista/windows7 since they have various write permissions (maybe), not to mention, no one like random files being added to their C drive.
I think its bad practice for important files like this to not be in the application folder…