How to get directory name of the page currently displaying

If you want to know only the directory name not the full path of the page that is currently displaying you can use this code

1
2
3
4
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Directory.Name.ToString();
Response.Write("<br><br>Directory name===" + sRet + "<br><br>");

Happy Coding

Najam Sikander Awan

comments powered by Disqus