Reputation: 522
I have a script lets say in folder 'root'. I have a folder inside root called 'Images', and inside images an image called 'logo.png'.
I have the following code to create a section:
Document document = new Document();
Section section = document.AddSection();
And I have tried this:
section.AddImage("../../Images/logo.png");
and this:
section.AddImage("Images/logo.png");
to try and add an image, but both return 'image not found'.
I've already tried updating MigraDoc to v1.5 but it didn't seem to work.
Upvotes: 0
Views: 1806
Reputation: 6111
Forgive me because I realize the age of this thread before providing an answer, but I too had the same issue that the accepted answer was unable to resolve.
In C# you are able to use HostingEnvironment.MapPath to reference relative paths. In your case, it'd look like:
section.AddImage(HostingEnvironment.MapPath("~/Images/logo.png"));
Upvotes: 0
Reputation: 21689
The "script" gets compiled and you get an assembly that is executed. You are using relative paths and by default the image will be searched relative to the working directory of the process which most likely is relative to the folder with the assembly. With ASP.NET things can be even more complicated.
Tip: The DocumentRenderer
class has a WorkingDirectory
property. If you set it then images with relative paths will be searched relative to this working directory. Set it to "root" and the second path "Images/logo.png" should work.
Upvotes: 1