Map File Path in Web API
To get the physical file path in Web API, you need to use "HostingEnvironment.MapPath()" method.
var sPath = System.Web.Hosting.HostingEnvironment.MapPath("/FilePath/");
You will need to apply this method when your application do not have access to HttpContext.Current properties, under the "System.Web" namespace. By default, an Asp.Net page refers to the System.Web to get access to various methods in the HttpContext class.
For example, "Server.CreateObject" or "Server.MapPath()" etc.
However, if you are "Self Hosting" a Web API application, then you will not have access to the HttpContext class. Typically, a Self Hosting application runs on its own process, that is, you are not hosting the application on the IIS. Therefore, the preferred method for getting the physical file path in a Web API application would be HostingEnvironment.MapPath().