How to locate an image without informing the absolute path?

3

How to locate an image without entering the absolute path?

Image img = System.Drawing.Image.FromFile("~/Content/images/SemFoto.jpg");

I tried in many ways and could not capture the image without telling the absolute path. The above line of code is in a action within a controller .     

asked by anonymous 03.11.2015 / 14:43

1 answer

5

I think this is what you want:

Image img = System.Drawing.Image.FromFile(
           System.Web.HttpContext.Current.Server.MapPath("~/Content/images/SemFoto.jpg"));

Documentation .

There are a few other ways to do this:

System.Web.Hosting.HostingEnvironment.MapPath(path);

Documentation .

The exact way you use it depends on how you're going to need it.

    
03.11.2015 / 14:52