开发者

Get Physical Folder site is running under

I am looking to get the folder that my website is running under. I have used many different methods within HttpContext.Current.Request but none of them were returning what I was looking for. I can easily get the value using substring but it doesn't look very clean and was wondering if there was a shorthand way of getting the folder.

For example when I use the code.

开发者_如何学C
HttpContext.Current.Server.MapPath("~")

I get C:\ClientProjects\Dev\v10.3\src\MySite

I can use:

HttpContext.Current.Server.MapPath("~").Substring(HttpContext.Current.Server.MapPath("~").LastIndexOf("\") + 1)

But this seems really bloated way to get the folder I'm running under.


You will be able to get the directory name from a System.IO.DirectoryInfo object.

Dim info As New System.IO.DirectoryInfo(HttpContext.Current.Server.MapPath("~"))
Dim name As String = info.Name ' name will have the value "MySite"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜