本文整理汇总了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);
}
}