Reputation: 13
I am using ASP.NET
application and I am trying to add a logo to PDF file and when I am not showing the full path, it says that the logo.png
does not exist.
I have tried to add this picture in many ways, but nothing except full path is working.
This is my code:
const string PngSamplePath = "/web_images/logo.png";
XImage image = XImage.FromFile(PngSamplePath);
gfx.DrawImage(image, 220, 120, 50, 50);
Upvotes: 1
Views: 3305
Reputation: 7204
FromFile
waits for a full path of the logo.
So you must use MapPath to resolve your relative path (~/web_images/logo.png
) to full path.
ASP.NET MVC1 -> MVC3
string path = HttpContext.Current.Server.MapPath("~/web_images/logo.png");
ASP.NET MVC4
string path = Server.MapPath("~/web_images/logo.png");
now path
become i.e: : C\MyApplication\web_images\logo.png
and then:
XImage image = XImage.FromFile(path)
Upvotes: 1
Reputation: 2494
It's hard to say without seeing your directory, however you can always just point to the root of your apps directory using the tilde (~
) and build from there.
"~/your/file/path.png"
Upvotes: 0