root web中的预配XlstViewWebPart让我在删除时不存在List

时间:2012-08-06 05:54:12

标签: sharepoint-2010

请考虑以下事项:

我有一个Admin子站点,其中包含所有列表和文档库,我使用XlstViewWebPart以编程方式在Root Web中配置大多数文档库,当我尝试选择一个项目并使用功能区上的删除按钮将其删除时:

服务器遇到以下错误: 列表不存在。您选择的页面包含一个不存在的列表。它可能已被其他用户删除。

但是如果从项目弹出菜单中删除项目,它工作正常并删除!!!!

平台:SharePoint Server 2010 SP1,VS 2010,CU 2012年6月

提前致谢

========================================

更新(我的代码以配置Web部件)

            Dim _web As SPWeb = SPContext.Current.Site.RootWeb

        Try
            'Get refrence to publishing web
            Dim _pubWeb As PublishingWeb = PublishingWeb.GetPublishingWeb(_web)
            Dim WPM As Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager

            If _pubWeb IsNot Nothing Then
                'Loop each publishing page in the web
                'Check out the file
                'If the current page have CustomWebPart (It is an Custom System Page), Then
                'If XsltListViewWebPart is not provisiond (double check in case of click the button more than one time), then
                'Create an XsltListViewWebPart
                'Assign properties of the new XsltListViewWebPart with Document Lib. Name and Admin web
                'Add the new XsltListViewWebPart to the current page in the loop
                For Each curPage As PublishingPage In _pubWeb.GetPublishingPages()
                    If curPage.ListItem.File.RequiresCheckout AndAlso curPage.ListItem.File.CheckOutType = SPFile.SPCheckOutType.None Then curPage.CheckOut()

                    WPM = curPage.ListItem.File.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared)

                    Dim CustomWebPart As CustomWebPart = WPM.WebParts.OfType(Of CustomWebPart)().FirstOrDefault()

                    If CustomWebPart IsNot Nothing Then
                        If CustomWebPart.DocLibName.ToLower = Constants.List.MeetingSchedular.ListName.ToLower Then Continue For

                        Dim web As SPWeb = _web.Site.RootWeb.Webs(Constants.WebNames.AdminWeb) 'Get Admin Web
                        Dim LVWP As WebPartPages.XsltListViewWebPart = WPM.WebParts.OfType(Of WebPartPages.XsltListViewWebPart)().FirstOrDefault()

                        If LVWP Is Nothing Then
                            LVWP = New WebPartPages.XsltListViewWebPart

                            Dim lst As SPList = web.Lists(CustomWebPart.DocLibName)

                            With LVWP
                                .WebId = web.ID
                                .ViewGuid = lst.DefaultView.ID.ToString("B").ToUpper()
                                .ListName = lst.ID.ToString("B").ToUpper()
                                .ListId = lst.ID
                                .ListUrl = "/Admin/" + CustomWebPart.DocLibName
                                .TitleUrl = "/Admin/" + CustomWebPart.DocLibName
                                .ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None
                                .AllowClose = False
                                .AllowEdit = True
                                .AllowMinimize = True
                                .AllowConnect = True
                            End With

                            _web.AllowUnsafeUpdates = True
                            WPM.AddWebPart(LVWP, "MainZone", 0)

                            curPage.Update()
                            _web.AllowUnsafeUpdates = False
                        End If

                        curPage.CheckIn("By cmdProvisionWebParts_Click")
                        curPage.ListItem.File.Publish("By cmdProvisionWebParts_Click")
                    End If
                Next
            End If
            RegisterNotification("Provision Web Parts Completed successfully")
        Catch ex As Exception
            SiteHelper.WriteErrors("Custom_Settings.ProvisioningRootWebParts", ex)
            RegisterNotification("Error: " + ex.Message)
        End Try

1 个答案:

答案 0 :(得分:0)

可能,错误发生是因为您的列表属于另一个站点(或子站点)而SP告诉您,它没有列表。 尝试在您的网站中创建列表并再次删除。 如果它不起作用,请向我们展示您的XlstViewWebPart代码。