public MapPath ( string virtualPath ) : string | ||
virtualPath | string | |
return | string |
string imagePath = Server.MapPath("~/images/logo.png");
string filePath = Server.MapPath("~/data/data.txt"); string fileContents = File.ReadAllText(filePath);In this example, the MapPath method is used to retrieve the physical path of the "data.txt" file located in the "data" folder within the web application. The contents of the file are then read using the File.ReadAllText method. The MapPath method is part of the System.Web.UI.Page class, which is included in the System.Web.dll library.