Monday, March 26, 2012

MapPath

Hello, I have a question:

If I have a folder:

rootFolder
+ include
+ links.txt
+ bin
+ images
+ processFile
+ file.aspx
+ processFile1
+ file2.aspx

Suppose that I have link.txt in include folder,

and I am in the page file.aspx, If I use HttpContext.Current.Request.MapPath("include/links.txt")
I will get the path as C:\inetpub\wwwroot\rootFolder\processFile\include\links.txt

If I use the MapPath in processFile1
I get : C:\inetpub\wwwroot\rootFolder\processFile2\include\links.txt

I want to use the MapPath so that it always gives me the path of

C:\inetpub\wwwroot\rootFolder\inlcude\links.txt

Is that possible ?

regardsHi,

you could try it like this:

Server.Mappath("~/include/links.txt")

Grz, Kris.
Hello, I would recommend this solution:


In the web.config:
--------
<add
name="host"
key="/mywebsite/" <!-- if Local, use the name of the website created by VS, if remote use "/"
/
StringBuilder strFile = new StringBuilder();
strFile.AppendFormat("{0}{1}",ConfigurationSettings.AppSettings["host"].ToString(),fname);
string path = HttpContext.Current.Server.MapPath(strFile.ToString());

This solution should work all the times.

regards

0 comments:

Post a Comment