删除列表项时Sharepoint对象模型中出现奇怪错误

删除列表项时Sharepoint对象模型中出现奇怪错误,sharepoint,sharepoint-2010,shared-libraries,Sharepoint,Sharepoint 2010,Shared Libraries,我得到了非常奇怪的错误,在过去的几个小时内解决了这个问题 当前不允许对GET请求进行更新。若要允许对GET进行更新,请在SPWeb上设置“AllowUnsafeUpdates”属性 公共共享子DeleteListItem(ByVal listname作为SPList,ByVal intItemID作为Integer) 将MySite用作新的SPSite(SPContext.GetContext(System.Web.HttpContext.Current.Web.Url) 使用MyWeb作为SP

我得到了非常奇怪的错误,在过去的几个小时内解决了这个问题

当前不允许对GET请求进行更新。若要允许对GET进行更新,请在SPWeb上设置“AllowUnsafeUpdates”属性

公共共享子DeleteListItem(ByVal listname作为SPList,ByVal intItemID作为Integer)
将MySite用作新的SPSite(SPContext.GetContext(System.Web.HttpContext.Current.Web.Url)
使用MyWeb作为SPWeb=MySite.OpenWeb()
MyWeb.AllowUnsafeUpdates=True
Dim ITEMCOL将登记为SPListItemCollection
Dim查询作为新的SPQuery()
query.query=”“&
intItemID&“
MyWeb.AllowUnsafeUpdates=True
ItemColCreditEnlist=listname.GetItems(查询)
如果ItemColEnlist.Count>0,则
对于i As Integer=listname.Items.Count-1到0步骤-1
如果listname.Items(i).ID=intItemID,则
MyWeb.AllowUnsafeUpdates=True
listname.Items.Delete(一)
listname.Update()
MyWeb.AllowUnsafeUpdates=False
如果结束
下一个
如果结束
终端使用
终端使用

请帮帮我

你试过调用
MyWeb.Update()吗直接在
MyWeb.AllowUnsafeUpdates=true之后
listname.Update()
调用可能是通过直接从web而不是当前上下文中表示该web的对象来检查此属性。这确实会产生一些问题,因为您需要多次调用该web/list上的update来启用和禁用该属性,并删除该项,所以请记住这一点

  Public Shared Sub DeleteListItem(ByVal listname As SPList, ByVal intItemID As Integer)

        Using MySite As New SPSite(SPContext.GetContext(System.Web.HttpContext.Current).Web.Url)

            Using MyWeb As SPWeb = MySite.OpenWeb()
                MyWeb.AllowUnsafeUpdates = True
                Dim itemColforGivenList As SPListItemCollection
                Dim query As New SPQuery()
             query.Query = "<Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>" &    
                intItemID & "</Value></Eq></Where>"
                MyWeb.AllowUnsafeUpdates = True
                itemColforGivenList = listname.GetItems(query)
                If itemColforGivenList.Count > 0 Then
                    For i As Integer = listname.Items.Count - 1 To 0 Step -1
                        If listname.Items(i).ID = intItemID Then
                            MyWeb.AllowUnsafeUpdates = True
                            listname.Items.Delete(i)
                            listname.Update()
                            MyWeb.AllowUnsafeUpdates = False
                        End If
                    Next

                End If

            End Using
        End Using