Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,



My url is "www.w3schools.com/Asp/sample.aspx" i want to remove folder in that url i.e "/Asp" to access another page how to do that
Posted
Comments
[no name] 21-May-14 8:34am    
Do you want to delete "/Asp" from the website?
Member 10226004 21-May-14 8:56am    
not from the website it should be removed from the URl link

1 solution

Here is the way you can get the new URL from current one :-

Ex

C#
string all = "www.w3schools.com/Asp/sample.aspx";
            string part = all.Substring(0, all.LastIndexOf('/'));
            string part1 = part.Substring(0, part.LastIndexOf('/'));
            string part2 = all.Substring(all.LastIndexOf('/'), all.Length-part.Length);
            string newURL = part1 + part2;


If you want to get the current URL dynamically then you can get like mentioned here in this post :-

http://forums.asp.net/t/1422355.aspx?Get+current+URL+in+ASP+NET[^]
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 21-May-14 9:19am    
To take URL string apart you better use Uri class - http://msdn.microsoft.com/en-us/library/vstudio/system.uri
SRS(The Coder) 22-May-14 0:35am    
I appreciate using the URI class but, i don't think we can get or remove the '/Asp' section from the URL just using this class. Any how we have use string operation. URI class can be used to get the whole URL or the section of the URL.

But we are not sure that the section '/Asp' is fixed here which needs to be removed but, it can be any folder name so string operation will be mandatory. We can only user URI class to get the URL or the domain or the rest part apart from domain.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900