从QuickLaunch中删除所有节点

时间:2014-02-17 12:09:36

标签: sharepoint sharepoint-2013 comexception

这是我删除QuickLaunch导航节点的代码。 我正在使用SharePoint 2013。

                public void 2013NodeOrders(string siteUrl, string quickLaunch)
            { 
            SPSecurity.RunWithElevatedPrivileges(() =>
                        {
                            using (var localWeb = new SPSite(siteUrl).OpenWeb())
                            {
                                try
                                {
                                    var ql = localWeb.Navigation.QuickLaunch;
                                    int count = 0;
                                    while (count++ < 10)
                                    {
                                        try
                                        {
                                            CleanUpAutoCreatedNodes(ql, nodeNames.ToArray());
                                            break;
                                        }
                                        catch (Exception ex)
                                        {}
                                    }
                                   localWeb.Update();
                                }
                                catch (Exception ex)
                                {
                                   Console.WriteLine("Error Occoured ", ex);
                                    throw ex;
                                }
                            }
                        });
            }

            private static void CleanUpAutoCreatedNodes(SPNavigationNodeCollection ql, string[] nodenames)
                    {
                        foreach (SPNavigationNode globalNode in ql)
                        {
                            if (Array.IndexOf(nodenames, globalNode.Title) == -1) 
                            {
                                if (globalNode.Children.Count > 0)
                                {
                                    foreach (SPNavigationNode childNode in globalNode.Children)
                                        childNode.Delete();
                                }
                                if (!globalNode.Title.Equals("Site Contents"))
                                    globalNode.Delete();
                            }
                        }
                    }

我从 foreach(ql中的SPNavigationNode globalNode) foreach(globalNode.Children中的SPNavigationNode childNode)

中获得了以下COM异常错误

错误讯息:         无法完成此操作。         请再试一次.x80004005

Stacktrace Error 

   at Microsoft.SharePoint.Library.SPRequestInternalClass.GetNavigationNodeChild(String bstrUrl, Int32 lParentId, Int32 lIndex, Int32& lNodeId, String& pbstrNodeUrl, String& pbstrName, String& pbstrNameResource, String& pbstrDateModified, Int32& pbIsVisible, Int32& pbIsExternal, Int32& plNumChildren, Guid& pgScopeId, Int32& plParentObjectType)
   at Microsoft.SharePoint.Library.SPRequest.GetNavigationNodeChild(String bstrUrl, Int32 lParentId, Int32 lIndex, Int32& lNodeId, String& pbstrNodeUrl, String& pbstrName, String& pbstrNameResource, String& pbstrDateModified, Int32& pbIsVisible, Int32& pbIsExternal, Int32& plNumChildren, Guid& pgScopeId, Int32& plParentObjectType)

1 个答案:

答案 0 :(得分:0)

您是否知道可以从SharePoint设计器中删除导航节点?