C# Get RelativeUrl from AbsoluteUrl

added by muraligolla
3/25/2011 12:48:29 PM

978 Views

Getting relativeUrl from absoluteUrl is very simple. We have a class System.Uri which takes absolute/full url as a string parameter and gives the relative url. using System; private static string GetRelativeUrl(string fullUrl) { try { Uri uri = new Uri(fullUrl);//fullUrl is absoluteUrl string relativeUrl = uri.AbsolutePath;//The Uri property AbsolutePath gives the relativeUrl return relativeUrl; } catch (Exception ex) { return fullUrl; //throw ex; } }


0 comments