One way of combining a base URL string with a relative path string in C#:


public void Combine_base_url_with_relative_path_test()
    Char slash = '/';

    // Make sure sharePointUrl does not end with a slash.
    string sharePointUrl = "https://mySharePointServer/sites/mysites";
    if (sharePointUrl.EndsWith(slash.ToString()))
        sharePointUrl = sharePointUrl.TrimEnd(slash);

    // Make sure templatesRelatviePath does not start with a slash.
    string templatesRelatviePath = "Shared Document/SubFolder1/SubFolder2";
    if (templatesRelatviePath.StartsWith(slash.ToString()))
        templatesRelatviePath = templatesRelatviePath.TrimEnd(slash);

    string templateAbsolutePath = string.Format("{0}{1}{2}", sharePointUrl, slash, templatesRelatviePath);
    // Assert
    Assert.AreEqual("https://mySharePointServer/sites/mysites/Shared Document/SubFolder1/SubFolder2", 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts