string configPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Web.config");
string imagePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/myImage.jpg"); if (File.Exists(imagePath)) { // serve up image } else { // return error }In this example, the method is used to ensure that the image exists at the specified virtual path before serving it up to the user. The System MapPath method is part of the System.Web assembly, which is included in the .NET Framework.