I want to use Server.MapPath() method im order to map a virtual directory I created to its physical path.
The thing is that the .net environment doesn't recognize Server.MapPath().
Google told me I'm supposed to use HttpContext.Current.Server using System.Web, but HttpContext isn't recognized in spite of me using System.Web. (And I've checked - HttpContext IS one of System.Web's classes)
Help?
The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.
If the path starts with either a forward slash(/) or backward slash(\) the MapPath Method returns a path as if the path is a full virtual path. If the path doesn't start with a slash, the MapPath Method returns a path relative to a directory of the . asp file being processed.
To get the physical file path in a Web API, you need to use HostingEnvironment. MapPath() method. var sPath = System.
Physical path - This is the actual path the file is located by IIS. Virtual path - This is the logical path to access the file which is pointed to from outside of the IIS application folder.
Make sure you have included System.Web in your projects References Do these (In Visual Studio IDE):
Server.MapPath should now be available.
If you have a web application, you should automatically have a reference to System.Web.dll
, and you should have access to the System.Web.HttpContext
class. Check that you haven't accidentally removed the reference. You would need a using System.Web;
statement to access the HttpContext
class without specifying the complete namespace.
If you don't have a web application you would have to add a referece to System.Web.dll
to get access to the HttpContext
class, but that would not help you a bit. As you are not in a web application, there is no HTTP context and there is no web root folder, so you can not use the MapPath method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With