Posts

Showing posts from October, 2013

Opening the current SPWeb

Image
I used to open the current SPWeb like so:   using (SPSite site = new SPSite(SPContext.Current.Web.Url))         {             using (SPWeb web = site.OpenWeb())             {             }         } However, if you access a SharePoint site with a URL that isn't in the alternate access mappings of the server, then the above code will create an error. File Not Found.   at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)    at Microsoft.SharePoint.SPSite..ctor(String requestUrl)    at wdCalendar_Services_GenerateSampleData.Page_Load(Object sender, EventArgs e)    at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)    at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)    at System.Web.UI.Control.OnLoad(EventArgs e)    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Page.ProcessRequestMain(Boolean inc