Need to write files to disk, how can I reference the folder in a web application?
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开发者_StackOverflow 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?
You can use Server.MapPath()
as in
Server.MapPath("~/files/ ")
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/");
Use Server.MapPath
http://msdn.microsoft.com/en-us/library/ms524632.aspx
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
精彩评论