Tuesday, August 19, 2008

Getting the URL path without the page filename in ASP.NET & C#

I needed to get the URL path of the current page object in ASP.NET and c# today, but without the filename part - e.g. myfile.aspx.

After a long hunt on the net re this, I found it was as simple as follows;

string pagePath = Page.TemplateSourceDirectory;

Hopefully this post will save someone else a long search!