Get the folder name of the current page ASP.NET C# -
i have navigation bar have inside bulletedlist. intention in doing able change classes based on current page sits on site. have code can find current filename, i want able retrieve name of folder current file located. how do this?
protected void page_load(object sender, eventargs e) { string[] file = request.currentexecutionfilepath.split('/'); string filename = file[file.length-1]; if (filename == "dashboard.aspx") { mainnavlist.items.findbytext("dashboard").attributes.add("class", "active"); } }
with httpcontext.current.request.url.absolutepath
can current url path.
as example if page visiting was:
http://www.website.com/directory1/directory2/page.aspx
then output string use split()
:
/directory1/directory2/page.aspx
Comments
Post a Comment