首页 > 代码库 > SharePoint开发 - 自定义导航菜单(三)附其他代码

SharePoint开发 - 自定义导航菜单(三)附其他代码

接上篇点击打开链接

LeftNavGroupTemplate.cs

internal class LeftNavGroupTemplate : ITemplate
    {
        // Fields
        private int index;
        private string xml;

        // Methods
        public LeftNavGroupTemplate(string _navXml, int _groupIndex)
        {
            this.xml = _navXml;
            this.index = _groupIndex;
        }

        public void InstantiateIn(Control container)
        {
            HtmlGenericControl child = new HtmlGenericControl("div");
            child.Style["width"] = "150px";
            child.Style["overflow"] = "hidden";
            DevExpress.Web.ASPxTreeView.ASPxTreeView view = new DevExpress.Web.ASPxTreeView.ASPxTreeView
            {
                ID = "tv" + this.index
            };
            view.Font.Name = "微软雅黑";
            view.Font.Size = new FontUnit("12px");
            view.TextField = "title";
            view.ToolTipField = "title";
            view.NavigateUrlField = "url";
            view.ImageUrlField = "imgurl";
            view.Width = new Unit("100%");
            XmlDataSource source = new XmlDataSource
            {
                ID = Guid.NewGuid().ToString(),
                Data = http://www.mamicode.com/this.xml>Item.cs
[Serializable]
    public class Item
    {
        // Properties
        [XmlAttribute]
        public string Path { get; set; }

        [XmlAttribute]
        public string Title { get; set; }

        [XmlAttribute]
        public string Url { get; set; }
    }
GlobalTab.cs
[Serializable]
    public class GlobalTab
    {
        // Methods
        public GlobalTab()
        {
            if (this.ItemCol == null)
            {
                this.ItemCol = new List<Item>();
            }
        }

        // Properties
        [XmlElement("Item")]
        public List<Item> ItemCol { get; set; }
    }
Config.cs

 internal class Config
    {
        // Methods
        public static GlobalTab Deserialize(string xml)
        {
            using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(GlobalTab));
                return (GlobalTab)serializer.Deserialize(stream);
            }
        }

        public static XmlDataSource GetDataSource(SPWeb web, NavType navType)
        {
            XmlDataSource source = new XmlDataSource();
            try
            {
                string innerXml = Load(web, navType);
                if (string.IsNullOrEmpty(innerXml))
                {
                    return source;
                }
                XmlDocument document = new XmlDocument();
                document.LoadXml(innerXml);
                if (!web.IsRootWeb && (document.DocumentElement.GetAttribute("Inherited").ToLower() == "true"))
                {
                    innerXml = LoadParent(web.ParentWeb, navType);
                    document.LoadXml(innerXml);
                }
                if (!web.UserIsSiteAdmin)
                {
                    XmlNodeList list = document.SelectNodes("//SiteMapNode[@SPGroups]");
                    for (int i = 0; i < list.Count; i++)
                    {
                        string[] strArray = list[i].Attributes["SPGroups"].Value.Split(new char[] { ';' });
                        bool flag = false;
                        foreach (string groupName in strArray)
                        {
                            if ((from g in web.Groups.Cast<SPGroup>() select g.Name).Contains<string>(groupName))
                            {
                                SPGroup group = web.Groups[groupName];
                                //flag = (from g in web.CurrentUser.Groups.Cast<SPGroup>() select g.Name).Contains<string>(group.Name);
                                flag = group.ContainsCurrentUser;
                            }
                            if (flag)
                            {
                                break;
                            }
                        }
                        if (!flag)
                        {
                            list[i].ParentNode.RemoveChild(list[i]);
                        }
                    }
                }
                foreach (XmlNode node in document.SelectNodes("//SiteMapNode[@url]"))
                {
                    string url = node.Attributes["url"].Value;
                    node.Attributes["url"].Value = http://www.mamicode.com/url.Replace("~site/", SPMIPUtility.GetRelative(web));>

SharePoint开发 - 自定义导航菜单(三)附其他代码