Building Solutions For Business That Make A Difference

Have Account! Sign In
Trailing Slash with SPWeb and/or SPSite URLs
  • Last Updated Date: 02-05-2018
  • Author: Rehman Khan

Sometimes you don’t know if you’ll get a trailing slash or not with a web.Url or site.Url. Use the method:

1
2
3
4
5
6
7
8
public static string EnsureTrailingSlash(string strUrl)
        {
            if (!strUrl.EndsWith("/", StringComparison.OrdinalIgnoreCase))
            {
                strUrl += "/";
            }
            return strUrl;
        }


Call like this:
SharedUrlUtility.EnsureTrailingSlash(SharedUserProfiles.MySiteHostUrl);

Hope this helps-
Rehman.