views:

266

answers:

1

I know you can do this:

if( System.IO.File.Exists(
    @"C:\INetPub\MVCWebsite\Content\Images\image.jpg") ) { ... }

and you can do this to reference files in MVC:

Url.Content("~/Content/Images/image.jpg")

So is there a way to relatively check that "~/Content/Images/image.jpg" exists (in MVC?)?

+6  A: 

Typically in ASP.NET, you would use a combination of Server.MapPath and File.Exists

Inside of a controller in ASP.NET MVC, you could use Request.MapPath as follows:

string filePath= Request.MapPath("~/Content/Images/image.jpg");
if( System.IO.File.Exists(filePath))
{
 //...
}
markt