Open Up A SharePoint Web Conditionally

This method shows you how you can open up a web conditionally based on pre-existing text, such as whether it exists in a text box in this specific example.
[csharp]

SPWeb web;
if (this.TextBox.Trim() == string.Empty)
{
        web = SPControl.GetContextWeb(this.Context);
}
else
{
        SPSite site = new SPSite(new Uri(this.Page.Request.Url, this.TextBox.Text, true).ToString());
        site.CatchAccessDeniedException = false;
        web = site.OpenWeb();
}

[/csharp]

Share

Leave a Reply

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