views:

38

answers:

4

In a web application, that may be installed anywhere on the filesystem, I need to figure out the path to the root of the installation folder.

I want to write xml files to the directory:

c:/installation/path/web_app/files/

Is this possible or do I have to store this path in the web.config?

+2  A: 

You can use Server.MapPath()

as in

Server.MapPath("~/files/ ")
David Stratton
+2  A: 

Assuming "web_app" in your example is always the root folder of your web application, you can reference the files like...

string path = Server.MapPath("/files/");
Steve Danner
A: 

You can use var rootFolder = Server.MapPath("~") to retrieve the physical path.

The tilde character ~ is replaced with the root directory of your web application, e.g. c:\installation\path\web_app

M4N