SharePoint开发 - 自定义导航菜单(二)母版页的菜单应用

接上篇点击打开链接

本篇叙述在母版页中应用之前的配置信息生成菜单,主要涉及到母版页的自定义,并应用了第三方控件库DevExpress,感兴趣的可以看看,这套东西很强大,戳这里

新建一个SharePoint项目,添加一个模块Module。Module会自动附带一个sample.txt的文件和一个Elements.xml的定义文件。我们删除掉没用的sample.txt,修改Elements.xml为如下所示

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="MasterPageModule" Url="_catalogs/masterpage">
    <File Path="Module\KBMaster.master" Url="KBMaster.master" Type="GhostableInLibrary"/>
  </Module>
</Elements>

母版页我们命名为KBMaster.master,这里需要说明的是,在2010中,添加项里是没有母版页的,我们可以通过VS创建一个web应用程序,在这个project里写母版页,写完之后再拷贝到Module下面去。母版页修改一般根据SP默认的最简母版页或者默认母版页进行修改(不要直接修改默认的东西),修改后的母版页核心代码如下(主要是添加菜单控件)

<div id="s4-workspace">
        <div id="s4-bodyContainer">
            <div id="s4-titlerow" class="s4-pr s4-notdlg s4-titlerowhidetitle">
                <div class="s4-title s4-lp">
                    <div class="s4-title-inner">
                        <table class="s4-titletable" cellspacing="0">
                            <tbody>
                                <tr>
                                    <td class="s4-titlelogo">
                                        <SharePoint:SPLinkButton runat="server" NavigateUrl="~site/" ID="onetidProjectPropertyTitleGraphic">
                                            <SharePoint:SiteLogoImage name="onetidHeadbnnr0" ID="onetidHeadbnnr2" LogoImageUrl="/_layouts/images/siteIcon.png"
                                                runat="server" />
                                        </SharePoint:SPLinkButton>
                                    </td>
                                    <td class="s4-titletext">
                                        <h1 name="onetidProjectPropertyTitle">
                                            <asp:ContentPlaceHolder ID="PlaceHolderSiteName" runat="server">
                                                <SharePoint:SPLinkButton runat="server" NavigateUrl="~site/" ID="onetidProjectPropertyTitle">
                                                    <SharePoint:ProjectProperty ID="ProjectProperty1" Property="Title" runat="server" />
                                                </SharePoint:SPLinkButton>
                                            </asp:ContentPlaceHolder>
                                        </h1>
                                        <span id="onetidPageTitleSeparator" class="s4-nothome s4-bcsep s4-titlesep">
                                            <SharePoint:ClusteredDirectionalSeparatorArrow ID="ClusteredDirectionalSeparatorArrow1"
                                                runat="server" />
                                        </span>
                                        <h2>
                                            <asp:ContentPlaceHolder ID="PlaceHolderPageTitleInTitleArea" runat="server" />
                                        </h2>
                                        <div class="s4-pagedescription" tabindex="0">
                                            <asp:ContentPlaceHolder ID="PlaceHolderPageDescription" runat="server" />
                                        </div>
                                    </td>
                                    <td class="s4-socialdata-notif">
                                        <SharePoint:DelegateControl ID="DelegateControl3" ControlId="GlobalSiteLink3" Scope="Farm"
                                            runat="server" />
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div id="s4-topheader2" class="s4-pr s4-notdlg">
                    <a name="startNavigation"></a>
                    <div id="s4-searcharea" class="s4-search s4-rp">
                        <asp:ContentPlaceHolder ID="PlaceHolderSearchArea" runat="server">
                            <SharePoint:DelegateControl ID="DelegateControl4" runat="server" ControlId="SmallSearchInputBox"
                                Version="4" />
                        </asp:ContentPlaceHolder>
                        <span class="s4-help"><span style="height: 17px; width: 17px; position: relative;
                            display: inline-block; overflow: hidden;" class="s4-clust"><a href="#" style="height: 17px;
                                width: 17px; display: inline-block;" onclick="TopHelpButtonClick('HelpHome');return false"
                                accesskey="<%$Resources:wss,multipages_helplink_accesskey%>" id="TopHelpLink"
                                title="<%$Resources:wss,multipages_helplinkalt_text%>" runat="server">
                                <img id="Img1" src="/_layouts/images/fgimg.png" alt="<%$Resources:wss,multipages_helplinkalt_text%>"
                                    style="left: -0px !important; top: -309px !important; position: absolute;" align="absmiddle"
                                    border="0" runat="server" />
                            </a></span></span>
                    </div>
                    <div class="s4-rp s4-app">
                    </div>
                    <div class="s4-lp s4-toplinks">
                        <asp:ContentPlaceHolder ID="PlaceHolderTopNavBar" runat="server">
                            <h2 class="ms-hidden">
                                <SharePoint:EncodedLiteral ID="EncodedLiteral5" runat="server" Text="<%$Resources:wss,topnav_pagetitle%>"
                                    EncodeMethod="HtmlEncode" /></h2>
                            <asp:ContentPlaceHolder ID="PlaceHolderHorizontalNav" runat="server">
                                <SharePoint:AspMenu ID="TopNavigationMenuV4" runat="server" EnableViewState="false"
                                    DataSourceID="topSiteMap" AccessKey="<%$Resources:wss,navigation_accesskey%>"
                                    UseSimpleRendering="true" UseSeparateCSS="false" Orientation="Horizontal" StaticDisplayLevels="1"
                                    MaximumDynamicDisplayLevels="2" SkipLinkText="" CssClass="s4-tn" />
                                <SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" ID="topNavigationDelegate">
                                    <Template_Controls>
                                        <asp:SiteMapDataSource ShowStartingNode="False" SiteMapProvider="SPNavigationProvider"
                                            ID="topSiteMap" runat="server" StartingNodeUrl="sid:1002" />
                                    </Template_Controls>
                                </SharePoint:DelegateControl>
                            </asp:ContentPlaceHolder>
                        </asp:ContentPlaceHolder>
                    </div>
                </div>
            </div>
            <div id="s4-statusbarcontainer">
                <div id="pageStatusBar" class="s4-status-s1">
                </div>
            </div>
            <SharePoint:VisualUpgradePreviewStatus ID="VisualUpgradePreviewStatus1" runat="server" />
            <div id="s4-mainarea" class="s4-pr s4-widecontentarea">
                <div id="s4-leftpanel" class="s4-notdlg">
                    <div>
                        <dx:ASPxNavBar ID="leftNav" runat="server" Width="100%" Font-Names="微软雅黑" Font-Size="12px"
                            AutoCollapse="True">
                            <GroupDataFields HeaderImageUrlField="imgurl" NameField="title" NavigateUrlField="url"
                                TextField="title" />
                        </dx:ASPxNavBar>
                    </div>
                    <div id="s4-leftpanel-content">
                        <asp:ContentPlaceHolder ID="PlaceHolderLeftNavBarDataSource" runat="server" />
                        <asp:ContentPlaceHolder ID="PlaceHolderCalendarNavigator" runat="server" />
                        <asp:ContentPlaceHolder ID="PlaceHolderLeftActions" runat="server">
                        </asp:ContentPlaceHolder>
                        <asp:ContentPlaceHolder ID="PlaceHolderLeftNavBarTop" runat="server" />
                        <asp:ContentPlaceHolder ID="PlaceHolderLeftNavBar" runat="server">
                            <div class="ms-quicklaunchouter">
                                <div class="ms-quickLaunch">
                                    <SharePoint:UIVersionedContent ID="UIVersionedContent1" runat="server" UIVersion="4">
                                        <contenttemplate>
						<h2 style="display:inline;" class="ms-hidden"><SharePoint:EncodedLiteral ID="EncodedLiteral6" runat="server" text="<%$Resources:wss,quiklnch_pagetitle%>" EncodeMethod="HtmlEncode"/></h2>
					</contenttemplate>
                                    </SharePoint:UIVersionedContent>
                                    <asp:ContentPlaceHolder ID="PlaceHolderQuickLaunchTop" runat="server">
                                        <SharePoint:UIVersionedContent ID="UIVersionedContent2" UIVersion="3" runat="server">
                                            <contenttemplate>
						<h3 class="ms-standardheader"><label class="ms-hidden"><SharePoint:EncodedLiteral ID="EncodedLiteral7" runat="server" text="<%$Resources:wss,quiklnch_pagetitle%>" EncodeMethod="HtmlEncode"/></label>
						<Sharepoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl1" runat="server" PermissionsString="ViewFormPages">
							<div class="ms-quicklaunchheader"><SharePoint:SPLinkButton id="idNavLinkViewAll" runat="server" NavigateUrl="~site/_layouts/viewlsts.aspx" Text="<%$Resources:wss,quiklnch_allcontent%>" accesskey="<%$Resources:wss,quiklnch_allcontent_AK%>"/></div>
						</SharePoint:SPSecurityTrimmedControl>
						</h3>
					</contenttemplate>
                                        </SharePoint:UIVersionedContent>
                                    </asp:ContentPlaceHolder>
                                    <SharePoint:SPNavigationManager ID="QuickLaunchNavigationManager" runat="server"
                                        QuickLaunchControlId="QuickLaunchMenu" ContainedControl="QuickLaunch" EnableViewState="false"
                                        CssClass="ms-quicklaunch-navmgr">
                                        <div>
                                            <SharePoint:DelegateControl ID="DelegateControl5" runat="server" ControlId="QuickLaunchDataSource">
                                                <Template_Controls>
                                                    <asp:SiteMapDataSource SiteMapProvider="SPNavigationProvider" ShowStartingNode="False"
                                                        ID="QuickLaunchSiteMap" StartingNodeUrl="sid:1025" runat="server" />
                                                </Template_Controls>
                                            </SharePoint:DelegateControl>
                                            <SharePoint:UIVersionedContent ID="UIVersionedContent3" UIVersion="3" runat="server">
                                                <contenttemplate>
					<SharePoint:AspMenu
						id="QuickLaunchMenu"
						runat="server"
						DataSourceId="QuickLaunchSiteMap"
						Orientation="Vertical"
						StaticDisplayLevels="2"
						ItemWrap="true"
						MaximumDynamicDisplayLevels="0"
						StaticSubMenuIndent="0"
						SkipLinkText=""
						CssClass="s4-die"
						>
						<LevelMenuItemStyles>
							<asp:MenuItemStyle CssClass="ms-navheader"/>
							<asp:MenuItemStyle CssClass="ms-navitem"/>
						</LevelMenuItemStyles>
						<LevelSubMenuStyles>
							<asp:SubMenuStyle CssClass="ms-navSubMenu1"/>
							<asp:SubMenuStyle CssClass="ms-navSubMenu2"/>
						</LevelSubMenuStyles>
						<LevelSelectedStyles>
							<asp:MenuItemStyle CssClass="ms-selectednavheader"/>
							<asp:MenuItemStyle CssClass="ms-selectednav"/>
						</LevelSelectedStyles>
					</SharePoint:AspMenu>
				</contenttemplate>
                                            </SharePoint:UIVersionedContent>
                                            <SharePoint:UIVersionedContent ID="UIVersionedContent4" UIVersion="4" runat="server">
                                                <contenttemplate>
					<SharePoint:AspMenu
					  id="V4QuickLaunchMenu"
					  runat="server"
					  EnableViewState="false"
					  DataSourceId="QuickLaunchSiteMap"
					  UseSimpleRendering="true"
					  UseSeparateCss="false"
					  Orientation="Vertical"
					  StaticDisplayLevels="2"
					  MaximumDynamicDisplayLevels="0"
					  SkipLinkText=""
					  CssClass="s4-ql" />
				</contenttemplate>
                                            </SharePoint:UIVersionedContent>
                                        </div>
                                    </SharePoint:SPNavigationManager>
                                    <SharePoint:UIVersionedContent ID="UIVersionedContent5" runat="server" UIVersion="3">
                                        <contenttemplate>
					<Sharepoint:SPNavigationManager
					id="TreeViewNavigationManager"
					runat="server"
					ContainedControl="TreeView"
					>
					  <table class="ms-navSubMenu1" cellpadding="0" cellspacing="0" border="0">
						<tr>
						  <td>
							<table class="ms-navheader" width="100%" cellpadding="0" cellspacing="0" border="0">
							  <tr>
								<td nowrap="nowrap" id="idSiteHierarchy">
								  <SharePoint:SPLinkButton runat="server" NavigateUrl="~site/_layouts/viewlsts.aspx" id="idNavLinkSiteHierarchy" Text="<%$Resources:wss,treeview_header%>" accesskey="<%$Resources:wss,quiklnch_allcontent_AK%>"/>
								</td>
							  </tr>
							</table>
						  </td>
						</tr>
					  </table>
					  <div class="ms-treeviewouter">
						<SharePoint:DelegateControl ID="DelegateControl6" runat="server" ControlId="TreeViewAndDataSource">
						  <Template_Controls>
							<SharePoint:SPHierarchyDataSourceControl
							 runat="server"
							 id="TreeViewDataSource"
							 RootContextObject="Web"
							 IncludeDiscussionFolders="true"
							/>
							<SharePoint:SPRememberScroll runat="server" id="TreeViewRememberScroll" onscroll="javascript:_spRecordScrollPositions(this);" style="overflow: auto;height: 400px;width: 150px; ">
							  <Sharepoint:SPTreeView
								id="WebTreeView"
								runat="server"
								ShowLines="false"
								DataSourceId="TreeViewDataSource"
								ExpandDepth="0"
								SelectedNodeStyle-CssClass="ms-tvselected"
								NodeStyle-CssClass="ms-navitem"
								NodeStyle-HorizontalPadding="2"
								SkipLinkText=""
								NodeIndent="12"
								ExpandImageUrl="/_layouts/images/tvplus.gif"
								CollapseImageUrl="/_layouts/images/tvminus.gif"
								NoExpandImageUrl="/_layouts/images/tvblank.gif"
							  >
							  </Sharepoint:SPTreeView>
							</Sharepoint:SPRememberScroll>
						  </Template_Controls>
						</SharePoint:DelegateControl>
					  </div>
					</Sharepoint:SPNavigationManager>
				</contenttemplate>
                                    </SharePoint:UIVersionedContent>
                                    <SharePoint:UIVersionedContent ID="UIVersionedContent6" runat="server" UIVersion="4">
                                        <contenttemplate>
					<Sharepoint:SPNavigationManager
					id="TreeViewNavigationManagerV4"
					runat="server"
					ContainedControl="TreeView"
					CssClass="s4-treeView"
					>
					  <SharePoint:SPLinkButton runat="server" NavigateUrl="~site/_layouts/viewlsts.aspx" id="idNavLinkSiteHierarchyV4" Text="<%$Resources:wss,treeview_header%>" accesskey="<%$Resources:wss,quiklnch_allcontent_AK%>" CssClass="s4-qlheader" />
						  <div class="ms-treeviewouter">
							<SharePoint:DelegateControl ID="DelegateControl7" runat="server" ControlId="TreeViewAndDataSource">
							  <Template_Controls>
								<SharePoint:SPHierarchyDataSourceControl
								 runat="server"
								 id="TreeViewDataSourceV4"
								 RootContextObject="Web"
								 IncludeDiscussionFolders="true"
								/>
								<SharePoint:SPRememberScroll runat="server" id="TreeViewRememberScrollV4" onscroll="javascript:_spRecordScrollPositions(this);" style="overflow: auto;height: 400px;width: 155px; ">
								  <Sharepoint:SPTreeView
									id="WebTreeViewV4"
									runat="server"
									ShowLines="false"
									DataSourceId="TreeViewDataSourceV4"
									ExpandDepth="0"
									SelectedNodeStyle-CssClass="ms-tvselected"
									NodeStyle-CssClass="ms-navitem"
									SkipLinkText=""
									NodeIndent="12"
									ExpandImageUrl="/_layouts/images/tvclosed.png"
									ExpandImageUrlRtl="/_layouts/images/tvclosedrtl.png"
									CollapseImageUrl="/_layouts/images/tvopen.png"
									CollapseImageUrlRtl="/_layouts/images/tvopenrtl.png"
									NoExpandImageUrl="/_layouts/images/tvblank.gif"
								  >
								  </Sharepoint:SPTreeView>
								</Sharepoint:SPRememberScroll>
							  </Template_Controls>
							</SharePoint:DelegateControl>
						  </div>
					</Sharepoint:SPNavigationManager>
				</contenttemplate>
                                    </SharePoint:UIVersionedContent>
                                    <asp:ContentPlaceHolder ID="PlaceHolderQuickLaunchBottom" runat="server">
                                        <SharePoint:UIVersionedContent UIVersion="3" runat="server" ID="PlaceHolderQuickLaunchBottomV3">
                                            <contenttemplate>
						<table width="100%" cellpadding="0" cellspacing="0" border="0" class="s4-die">
						<tr><td>
						<table class="ms-recyclebin" width="100%" cellpadding="0" cellspacing="0" border="0">
						<tr><td nowrap="nowrap">
						<SharePoint:SPLinkButton runat="server" NavigateUrl="~site/_layouts/recyclebin.aspx" id="v3idNavLinkRecycleBin" ImageUrl="/_layouts/images/recycbin.gif" Text="<%$Resources:wss,StsDefault_RecycleBin%>" PermissionsString="DeleteListItems" />
						</td></tr>
						</table>
						</td></tr>
						</table>
					</contenttemplate>
                                        </SharePoint:UIVersionedContent>
                                        <SharePoint:UIVersionedContent UIVersion="4" runat="server" ID="PlaceHolderQuickLaunchBottomV4">
                                            <contenttemplate>
						<ul class="s4-specialNavLinkList">
							<li>
								<SharePoint:ClusteredSPLinkButton
									runat="server"
									NavigateUrl="~site/_layouts/recyclebin.aspx"
									ImageClass="s4-specialNavIcon"
									ImageUrl="/_layouts/images/fgimg.png"
									ImageWidth=16
									ImageHeight=16
									OffsetX=0
									OffsetY=428
									id="idNavLinkRecycleBin"
									Text="<%$Resources:wss,StsDefault_RecycleBin%>"
									CssClass="s4-rcycl"
									PermissionsString="DeleteListItems" />
							</li>
							<li>
								<SharePoint:ClusteredSPLinkButton
									id="idNavLinkViewAllV4"
									runat="server"
									PermissionsString="ViewFormPages"
									NavigateUrl="~site/_layouts/viewlsts.aspx"
									ImageClass="s4-specialNavIcon"
									ImageUrl="/_layouts/images/fgimg.png"
									ImageWidth=16
									ImageHeight=16
									OffsetX=0
									OffsetY=0
									Text="<%$Resources:wss,quiklnch_allcontent_short%>"
									accesskey="<%$Resources:wss,quiklnch_allcontent_AK%>"/>
							</li>
						</ul>
					</contenttemplate>
                                        </SharePoint:UIVersionedContent>
                                    </asp:ContentPlaceHolder>
                                </div>
                            </div>
                        </asp:ContentPlaceHolder>
                    </div>
                </div>
                <div class="s4-ca s4-ca-dlgNoRibbon" id="MSO_ContentTable">
                    <div class="s4-die">
                        <asp:ContentPlaceHolder ID="PlaceHolderPageImage" runat="server" Visible="false" />
                        <asp:ContentPlaceHolder ID="PlaceHolderTitleLeftBorder" runat="server" Visible="false">
                        </asp:ContentPlaceHolder>
                        <div id="onetidPageTitleAreaFrame" class='ms-pagetitleareaframe s4-pagetitle'>
                        </div>
                        <asp:ContentPlaceHolder ID="PlaceHolderMiniConsole" runat="server" Visible="false" />
                        <span class="s4-die">
                            <asp:ContentPlaceHolder ID="PlaceHolderTitleRightMargin" runat="server" Visible="false" />
                        </span>
                        <asp:ContentPlaceHolder ID="PlaceHolderTitleAreaSeparator" runat="server" Visible="false" />
                        <asp:ContentPlaceHolder ID="PlaceHolderNavSpacer" runat="server" Visible="false">
                            <img src="/_layouts/images/blank.gif" width='138' height='1' alt="" /></asp:ContentPlaceHolder>
                        <asp:ContentPlaceHolder ID="PlaceHolderLeftNavBarBorder" runat="server" Visible="false">
                        </asp:ContentPlaceHolder>
                        <asp:ContentPlaceHolder ID="PlaceHolderBodyLeftBorder" runat="server" Visible="false">
                        </asp:ContentPlaceHolder>
                    </div>
                    <SharePoint:VersionedPlaceHolder UIVersion="3" ID="DesignModeConsoleV3" runat="server">
                        <asp:ContentPlaceHolder ID="WSSDesignConsole" runat="server">
                            <wssuc:DesignModeConsole ID="IdDesignModeConsole" runat="server" />
                        </asp:ContentPlaceHolder>
                    </SharePoint:VersionedPlaceHolder>
                    <div class='s4-ba'>
                        <div class='ms-bodyareacell'>
                            <div id="MSO_ContentDiv" runat="server">
                                <a name="mainContent"></a>
                                <asp:ContentPlaceHolder ID="PlaceHolderMain" runat="server">
                                </asp:ContentPlaceHolder>
                            </div>
                        </div>
                    </div>
                    <div class="s4-die">
                        <asp:ContentPlaceHolder ID="PlaceHolderBodyRightMargin" runat="server">
                        </asp:ContentPlaceHolder>
                    </div>
                </div>
            </div>
            <SharePoint:DeveloperDashboard ID="DeveloperDashboard1" runat="server" />
        </div>
    </div>

后台主要做的就是从配置XML里面获取到数据,然后让菜单控件根据这个配置信息生成菜单

public partial class KBMaster : MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.prepareTopNav();
            this.prepareLeftNav();
        }

        private void prepareLeftNav()
        {
            XmlDataSource dataSource = Config.GetDataSource(SPContext.Current.Web, Config.NavType.Left);
            if (string.IsNullOrEmpty(dataSource.Data))
            {
                this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "LeftNav", "<script>document.getElementById('s4-leftpanel-content').style.display = 'block';</script>");
            }
            else
            {
                int num;
                bool isAdmin = SPContext.Current.Web.CurrentUser.IsSiteAdmin;
                if (!isAdmin)
                {
                    this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "LeftNav", "<script>document.getElementById('s4-leftpanel-content').style.display = 'none';</script>");
                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "LeftNav", "<script>document.getElementById('s4-leftpanel-content').style.display = 'block';</script>");
                }
                this.leftNav.DataSource = dataSource;
                this.leftNav.DataBind();
                for (num = 0; num < this.leftNav.Groups.Count; num++)
                {
                    this.leftNav.Groups[num].ContentTemplate = new LeftNavGroupTemplate(dataSource.Data, num);
                    DevExpress.Web.ASPxTreeView.ASPxTreeView view = (DevExpress.Web.ASPxTreeView.ASPxTreeView)this.leftNav.Groups[num].FindControl("tv" + num);
                    if (view.SelectedNode != null)
                    {
                        view.ExpandToNode(view.SelectedNode);
                        this.leftNav.Groups[num].Expanded = true;
                    }
                }
            }
        }

        private void prepareTopNav()
        {
            if (this.TopNavigationMenuV4 != null)
            {
                try
                {
                    XmlDataSource dataSource = Config.GetDataSource(SPContext.Current.Web, Config.NavType.Top);
                    if (!string.IsNullOrEmpty(dataSource.Data))
                    {
                        this.TopNavigationMenuV4.DataSource = dataSource;
                        this.TopNavigationMenuV4.DataSourceID = "";
                        this.TopNavigationMenuV4.DataBindings.Clear();
                        MenuItemBinding binding = new MenuItemBinding
                        {
                            DataMember = "SiteMapNode",
                            TextField = "title",
                            ValueField = "title",
                            NavigateUrlField = "url"
                        };
                        this.TopNavigationMenuV4.DataBindings.Add(binding);
                    }
                    else
                    {
                        this.TopNavigationMenuV4.DataSource = null;
                        this.TopNavigationMenuV4.DataSourceID = "topSiteMap";
                    }
                    this.TopNavigationMenuV4.DataBind();
                }
                catch (Exception exception)
                {
                    SPMIPTrace.WriteError("SPMIPNavigation", exception);
                    this.TopNavigationMenuV4.DataSource = null;
                    this.TopNavigationMenuV4.DataSourceID = "topSiteMap";
                    this.TopNavigationMenuV4.DataBindings.Clear();
                    this.TopNavigationMenuV4.DataBind();
                }
            }
        }
    }

篇幅有限,其他代码将在下一篇附上

接下来处理feature的事件,在激活时应用母版页,在取消激活时还原默认母版页

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite parent = (SPSite)properties.Feature.Parent;
            SPWeb rootWeb = parent.RootWeb;
            rootWeb.MasterUrl = "/_catalogs/masterpage/KBMaster.master";
            rootWeb.Update();
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite parent = (SPSite)properties.Feature.Parent;
            SPWeb rootWeb = parent.RootWeb;
            rootWeb.MasterUrl = "/_catalogs/masterpage/v4.master";
            rootWeb.Update();
        }
时间: 2024-11-02 22:27:38

SharePoint开发 - 自定义导航菜单(二)母版页的菜单应用的相关文章

SharePoint开发 - 自定义导航菜单(一)菜单声明与配置

本篇描述自定义sharepoint菜单的一种方式,自定义菜单适用于一些门户等需求的网站 自定义的菜单有自己的数据源,可以是数据表,可以是XML,本篇叙述的是采用XML数据源作为菜单的声明定义部分,将XML以文件的格式保存到网站中自己创建的配置文档库中 XML菜单的格式形如下面的格式,其中有菜单标题title属性,有菜单所属的权限用户组SPGroups属性,有菜单的链接url属性,实际应用中可以添加更多的字段. <SiteMap> <SiteMapNode title="我的项目

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 = _groupInde

SharePoint开发 - 自定义页面(错误页、登出页)

本文叙述如何自定义SharePoint的固有页面,比较简单,用一句话说就是“做个页面,写一句代码.” 创建SharePoint空解决方案,添加Layouts映射文件夹,添加页面文件error.aspx和signout.aspx. error.aspx [html] view plaincopyprint? <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <%@ Import Namespace=

SharePoint 2013 自定义扩展菜单(二)

原文:SharePoint 2013 自定义扩展菜单(二) 接博文<SharePoint 2013 自定义扩展菜单>,多加了几个例子,方便大家理解. 例七 列表设置菜单扩展(listedit.aspx) 扩展效果 XML描述 <CustomAction Id="CustomAction1" Description="博客园-霖雨" Title="博客园-霖雨" GroupId="GeneralSettings"

discuzx3.2后台管理菜单定制,管理菜单二次开发,discuzx3.2后台管理菜单自定义

discuzx3.2后台管理菜单定制,管理菜单二次开发 详情请参考:http://www.infosz.com/forum.php?mod=viewthread&tid=199 第一步:source\admincp\menu下添加 menu_infosz.php,内容如下: 第二步:source\admincp目录下添加admincp_infosz.php 文件,内容如下: 第三步: source\language\lang_admincp_menu.php添加如下内容: 第四步:source\

SharePoint 2013 自定义扩展菜单

原文:SharePoint 2013 自定义扩展菜单 在对SharePoint进行开发或者功能扩展的时候,经常需要对一些默认的菜单进行扩展,以使我们开发的东西更适合SharePoint本身的样式.SharePoint的各种功能菜单,像网站设置.Ribbon.列表里的下拉等等,都是一样原理的,都是XML+JS脚本实现的,如果想实现这些功能,只需要一个XML发布成Feature,并在网站功能启用,即可. 其实,关于这个并没有什么过多可以说的东西,大家在实践中,渐渐理解了.下面,我就举几个简单的例子,

SharePoint 2013:自定义ECB菜单项的添加

本文分别介绍了两种常用的添加ECB菜单项的方式. 声明式创建 这也是微软最佳实践推荐的方式.在VS中创建一个SharePoint空解决方案,并添加一个“空元素”类型的SPI. 在Elements.xml中,定义一个CustomAction,重点关注一下其中高亮部分的属性(本例在文档内容类型的项上添加了一个菜单项,点击导航到一个自定义应用程序页面,并传递项所在的列表的Id作为参数): 添加到Feature,并部署.效果如下: 服务器对象模型创建 这里会用到Feature的事件处理程序.本例同时还演

每日学习心得:SharePoint 2013 自定义列表项添加Callout菜单项、文档关注、SharePoint服务端对象模型查询

前言: 前一段时间一直都比较忙,没有什么时间进行总结,刚好节前项目上线,同时趁着放假可以好好的对之前遇到的一些问题进行总结.主要内容有使用SharePoint服务端对象模型进行查询.为SharePoint 自定义列表项添加callout菜单.希望能够给大家带来一些帮助. 1.  在aspx页引用可视化Web部件 有时候会需要在页面中引用项目中创建的可视化Web部件,具体步骤有以下这几步: 1) 在aspx页面顶部注册该可视化Web部件 示例如下: <%@ Register Tagprefix=&qu

SharePoint 2013开发入门探索(二)- 列表操作

我们如何用代码对SharePoint列表做些例如增删改查的操作呢?如果您的程序可以部署到服务器上,就可以使用 服务器对象模型,因为服务器对象模型提供的功能最多,限制最少:否则可能要选择客户对象模型等其他方式,这可能会遇到一些功能限制:另外还有一些其他的访问方式,例如Web服务等.如何在 SharePoint 2013 中选择正确的 API 集请参考链接 http://msdn.microsoft.com/zh-cn/library/jj164060.aspx. 我们首先研究下服务器对象模型.使用