14 October, 2013
0 Comments
1 category
One way of combining a base URL string with a relative path string in C#:
[TestMethod] 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", templateAbsolutePath); }
Tags: C#
Category: Uncategorized