0

i have a problem, i wanted to shorten filepath to my image

xlWorkSheet.Shapes.AddPicture("C:\\Users\my.name\\source\\repos\test\test\\Resource\\dog.jpg", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left4+10, Top4+12, -1, -1);

to be something like this

xlWorkSheet.Shapes.AddPicture("\\Resource\\dog.jpg", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left4+10, Top4+12, -1, -1)

i need to change it because my program will be used on different computers so users will not have the same filepath

1 Answers1

0

The simplest way to do this would be to use an embedded resource with a temporary file.

First, add the image to your project and set it as an embedded resource. You can set it as an embedded resource in Visual Studio by selecting the file in the Solution Explorer window and hitting the F4 button, then changing the "Build Action" to "Embedded Resource".

Then, you'll need to pull that image out of your DLL and write it out to a temporary file. How can I extract a file from an embedded resource and save it to disk? https://learn.microsoft.com/en-us/dotnet/api/system.io.path.gettempfilename

Lastly, use your new temporary file path as the argument to your AddPicture method.

Victor Wilson
  • 1,720
  • 1
  • 11
  • 22