Reputation: 1817
Ive got a working webmail and i want to send an embedded image.
LinkedResource imagelink = new LinkedResource(Server.MapPath(".") + @"..\Content\img\GladSmiley.png", "image/png");
when i use the code above it will search for the mappath to the image witch is located in the \projectname\content\img folder. But the mappath method is looking for the img in \projectname\home\content\img so by some reason it adds the home-folder to the mappath :S Is there a way to go around this problem? or am i doing something wrong?
Upvotes: 1
Views: 157
Reputation: 14941
Try this instead:
LinkedResource imagelink = new LinkedResource(HostingEnvironment.MapPath("~/Content/img/GladSmiley.png"), "image/png");
The relevant bit is that you find the directory/file like this:
HostingEnvironment.MapPath("~/Content/img/GladSmiley.png")
You can also use Server.MapPath
with exactly the same syntax if you want, but you need an HttpContext to do that (which you probably have, but for the sake of making it always work, use HostingEnvironment.MapPath
).
HostingEnvironment.MapPath("~/Content/img/GladSmiley.png") // works everywhere
Server.MapPath("~/Content/img/GladSmiley.png") // needs HttpContext
See this discussion for more information if you're interested: What is the difference between Server.MapPath and HostingEnvironment.MapPath?
Upvotes: 1