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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -