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

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

1 Response so far »

  1. 1

    Sunny said,

    Hi Najam,

    This is really great…and very simple 4 line code to get the directory name from the URL….


Comment RSS · TrackBack URI

Say your words