当前位置: 首页>>代码示例>>C#>>正文


C# MenuItemCollection.AddAt方法代码示例

本文整理汇总了C#中System.Web.UI.WebControls.MenuItemCollection.AddAt方法的典型用法代码示例。如果您正苦于以下问题:C# MenuItemCollection.AddAt方法的具体用法?C# MenuItemCollection.AddAt怎么用?C# MenuItemCollection.AddAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.UI.WebControls.MenuItemCollection的用法示例。


在下文中一共展示了MenuItemCollection.AddAt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadNavigation

        /// <summary>
        /// Loops through the list items in the MyNiem List and gets the navigation based on access.
        /// </summary>
        /// <param name="List"></param>
        protected void LoadNavigation(SPList List)
        {
            try
            {
                if (Page.User.Identity.IsAuthenticated)
                {
                    SPListItemCollection Items = List.Items;
                    var PersonalNav = LoginView1.FindControl("PersonalNav") as AspMenu;
                    MenuItemCollection MenuItems = new MenuItemCollection();

                    //grabs the items in the list then loops through the webs the user currently has access too
                    foreach (SPListItem Item in Items)
                    {
                        //old code to recursively check if the user has access to the subweb
                        //if (Web.Url.ToLower() == SPContext.Current.Web.Site.RootWeb.Url.ToLower() + "/" + Item["Title"].ToString().ToLower())
                        //    FoundWeb = true;
                        //else
                        //    FoundWeb = GetSubWebs(Web, SPContext.Current.Web.Site.RootWeb.Url.ToLower() + "/" + Item["Title"].ToString().ToLower(), FoundWeb);
                        //Guid SiteGuid = SPContext.Current.Site.ID;
                        string SiteURL = SPContext.Current.Web.Site.RootWeb.Url.ToLower();
                        SPUser CurrentUser = SPContext.Current.Web.CurrentUser;
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            #region OldCode
                            //    if (FoundWeb)
                            //    {
                            //        using (SPSite Site = new SPSite(SPContext.Current.Web.Site.RootWeb.Url.ToLower() + "/" + Item["Title"].ToString()))
                            //        {
                            //            using (SPWeb FoundSubWeb = Site.OpenWeb())
                            //            {
                            //                MenuItem MyNiemItem = new MenuItem(FoundSubWeb.Title, FoundSubWeb.Title, "", FoundSubWeb.Url);
                            //                int CompareNumber = 0;
                            //                for(int i=0;i<MenuItems.Count && CompareNumber>=0;i++)
                            //                {
                            //                    string CompareItem = MyNiemItem.Text;
                            //                    CompareNumber = CompareItem.CompareTo(MenuItems[i].Text);
                            //                    if(CompareNumber < 0)
                            //                        MenuItems.AddAt(i, MyNiemItem);
                            //                }
                            //                if(CompareNumber>=0)
                            //                    MenuItems.Add(MyNiemItem);
                            //                FoundWeb = false;
                            //            }
                            //        }
                            //    }
                            //}
                            //foreach (MenuItem Item in MenuItems)
                            //{
                            //    PersonalNav.Items.Add(Item);
                            //}
                            #endregion

                            //new code to check against site
                            using (SPSite Site = new SPSite(SiteURL + "/" + Item["Title"].ToString()))
                            {
                                using (SPWeb Web = Site.OpenWeb())
                                {
                                    if (Web.DoesUserHavePermissions(CurrentUser.LoginName, SPBasePermissions.Open))
                                    {
                                        MenuItem MyNiemItem = new MenuItem(Web.Title, Web.Title, "", Web.Url);
                                        int CompareNumber = 0;
                                        for (int i = 0; i < MenuItems.Count && CompareNumber >= 0; i++)
                                        {
                                            string CompareItem = MyNiemItem.Text;
                                            CompareNumber = CompareItem.CompareTo(MenuItems[i].Text);
                                            if (CompareNumber < 0)
                                                MenuItems.AddAt(i, MyNiemItem);
                                        }
                                        if (CompareNumber >= 0)
                                            MenuItems.Add(MyNiemItem);
                                    }
                                }
                            }

                        });
                    }
                    foreach (MenuItem Item in MenuItems)
                    {
                        PersonalNav.Items.Add(Item);
                    }
                }
            }
            catch (SPException ex)
            {
                UpdateErrorLog(ex);
            }
        }
开发者ID:NIEM-Web,项目名称:Sharepoint,代码行数:91,代码来源:PersonalMenu.ascx.cs


注:本文中的System.Web.UI.WebControls.MenuItemCollection.AddAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。