MOSS添加删除导航结点代码示例(SPNavigationNode)

添加导航栏

                SPSite site = new SPSite(siteurl);
                SPWeb web = site.OpenWeb();


                SPList list = web.Lists["取件客服受理"];
                string listtitle = list.Title;          //列表名称
                string listurl = list.DefaultViewUrl;   //列表URL

                #region    添加一级导航栏
                SPNavigationNodeCollection navigationnode = web.Navigation.QuickLaunch;
                SPNavigationNode menuItem = new SPNavigationNode(listtitle, listurl, true);
                navigationnode.AddAsLast(menuItem);              
                #endregion

                #region   添加二级导航栏
                SPNavigationNode menuItem1 = new SPNavigationNode(listtitle, listurl, true);
                navigationnode[1].Children.AddAsLast(menuItem1);
                #endregion

                web.Update();

 

删除导航栏

                int menuItemId = 0;
                SPNavigationNode menuItem = navigationnode.Navigation.GetNodeById(menuItemId);
                navigationnode.Delete(menuItem);

                int menuItemId = 0;
                SPNavigationNode menuItem = navigationnode.Navigation.GetNodeById(menuItemId);
                navigationnode.Delete(navigationnode[0]);


 

你可能感兴趣的:(node)