Wednesday, 25 January 2012

How to use LasIndexOf in "URL"

string projecturl = properties.WebUrl;
string targeturl = projecturl.Remove(projecturl.LastIndexOf('/'));

Example
string sp=http://sharepoint/sites/subsite1/subsite2

here I want to remove subsite2 from the above url

string newsp=sp.Remove(sp.LastIndexOf('/'));

now we get the URL as

http://sharepoint/sites/subsite1