I have following code in my web part. I want to know whether this property _web will create object each time whenever I use it. If yes then will it be disposed every time.
private SPWeb _web
{
get
{
using (SPSite site = new SPSite(<SiteURL>))
{
return site.OpenWeb();
}
}
}
Will appreciate immediate response.
Update:
@Evariste: We are using this code in SharePoint 2013 application page deployed as site collection feature.
Getting below stack trace of error in ULS.
Unexpected 00000000-0000-0000-0000-000000000000 Stack trace: at Microsoft.SharePoint.SPListCollection.GetListByName(String strListName, Boolean bThrowException) at AgreementApprovalRequest.Layouts.AgreementApprovalRequest.CreateNewAggApprRequest.GetDetailFromUI() at AgreementApprovalRequest.Layouts.AgreementApprovalRequest.CreateNewAggApprRequest.saveFormDetails() at AgreementApprovalRequest.Layouts.AgreementApprovalRequest.CreateNewAggApprRequest.BtnSubmit_Click(Object sender, EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error) at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) 78635e9d-13dc-e0ea-fac5-34124891f447
Code:
Getting Error in two different places. Shown below
SPList docLibrary = _web.Lists[ListName.LegalAgreementTemplate.ToString()];
using (SPSite site = new SPSite(_web.Url))
Regards,
Nafe