private static void CreateManagedPath(string path, SPWebApplication webApp) { SPPrefixCollection prefixColl = webApp.Prefixes; if (prefixColl.Contains(path) == false) { SPPrefix newPrefix = webApp.Prefixes.Add(path, SPPrefixType.ExplicitInclusion); } }
/// <summary> /// Adds the managed path. /// </summary> /// <param name="targetUrl">The target URL.</param> /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param> private static void AddManagedPath(string targetUrl, bool haltOnWarning) { string serverRelUrlFromFullUrl = Utilities.GetServerRelUrlFromFullUrl(targetUrl); serverRelUrlFromFullUrl = serverRelUrlFromFullUrl.Trim(new char[] { '/', '*' }); SPWebApplication webApp = SPWebApplication.Lookup(new Uri(targetUrl)); SPPrefixCollection prefixCollection = webApp.Prefixes; if (prefixCollection.Contains(serverRelUrlFromFullUrl)) { if (haltOnWarning) { throw new SPException("Managed path already exists."); } else { Logger.WriteWarning("Managed path already exists."); } return; } prefixCollection.Add(serverRelUrlFromFullUrl, SPPrefixType.ExplicitInclusion); }