2013-03-29 99 views
1

在HTML中的相對路徑,我知道我可以指定如相對路徑:指定服務器端代碼

<a href="~/temp/Somecontent.xxx" />

我想設置相對路徑爲我的服務器端代碼。例如:

File.Exists("../myBusinessLibrary/Bin/Debug/myBusinessLibrary.dll");//where this is a library that supports the web project

文件不能被發現。我看着Environment.CurrentDirectory並獲得:

"C:\\Program Files (x86)\\IIS Express"

我不認爲我的程序集被複制到這個位置做。有沒有辦法設置與服務器端代碼一起工作的相對路徑?

回答

4

您可以使用下面的代碼

HttpContext.Current.Server.MapPath("relativepath goes here") 
2

您可以使用Server.MapPath

var path = Server.MapPath("/myBusinessLibrary/Bin/Debug/myBusinessLibrary.dll"); 

File.Exists(path);