I have this url (www.site.com/folder1/sub-folder)
Now I just want to get only folder1 from this url. How can I do that? I'm getting Last root url from below code but I want only first root url.
string s = Page.Request.Url.AbsolutePath;
s = s.Substring(s.LastIndexOf("/")+1);
You can use
Split() method twice like
string str = "www.site.com/folder1/sub-folder"; string folder = (str.Split('/')).Split('/');