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.
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");
If you're using a console application project template or any other template other than Web application then you have to add a reference to System.Web.
You will then be able to refer to the System.Web.Hosting namespace.
Hope this helps!
精彩评论