Archive for November, 2007

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

Leave a comment »

How to get pagename of itself

 If you want to display the filename or page name of the current displaying page just use these two lines and it will show only the filename like default.aspx, najam.aspx or indexas.aspx no matter it these pages are located deep into your site structure.

string pagename = System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"]); Response.Write(pagename);

Enjoy coding

Najam Sikander Awan

Comments (1) »