Я пытаюсь программно добавить новый элемент ListItem в уже существующий список на моем сайте SharePoint 2010.
Я создал новую веб-часть, добавил к ней одну кнопку со следующим обработчиком событий
protected void Unnamed1_Click(object sender, EventArgs e)
{
using (SPSite currentSiteCollection = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb currentWebsite = currentSiteCollection.OpenWeb(SPContext.Current.Web.ID))
{
SPListItem myNewItem = currentWebsite.Lists["myList"].AddItem();
myNewItem["Title"] = "newItem1";
myNewItem.Update();
}
}
}
Добавил мою веб-часть на страницу по умолчанию на сайте sharepoint 2010 ... к сожалению, когда я нажимаю кнопку, я получаю эту ошибку
Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[COMException (0x80030102): Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))]
Microsoft.SharePoint.Library.SPRequestInternalClass.SetDisableAfterEvents(Boolean bNewDisableAfterEvents) +0
Microsoft.SharePoint.Library.SPRequest.SetDisableAfterEvents(Boolean bNewDisableAfterEvents) +124
[SPException: Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))]
Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) +27677298
Microsoft.SharePoint.Library.SPRequest.SetDisableAfterEvents(Boolean bNewDisableAfterEvents) +207
Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents, String filename) +26793884
Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents, String filename) +26793214
Microsoft.SharePoint.SPListItem.Update() +161
SLBWOA.Web.UCNewChecklist.UCNewChecklistUserControl.Unnamed1_Click(Object sender, EventArgs e) +259
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
Я пробовал несколько решений, доступных на форуме и через Google, но безуспешно.