C# – Getting IIS Application filesystem path

asp.netciisiis-7net

I have IIS 7.0 installed on and there is a .net application with a .svc service there.

I would like to point a file in the virtual directory pointed by the application (please note that I converted my virtual dir in an application).

However, when I try to open a file, using a general api call in the .net-verse, and do not specify a root (complete) path but relative, I end up in the error when a resource is not found.

How can I obtain the physical path of my app?

Note that this is a web application. It cannot use the Request object because it needs to make this call from the web service, hosted by my app.

Best Answer

try this might help to resolve your issue

string apPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;

or

string apPath = System.Web.Hosting.HostingEnvironment.MapPath("~/folder/file");