SharePoint development-Customizing the Navigation menu (i) menu declaration and configuration

Source: Internet
Author: User
Tags bool

Blog Address Http://blog.csdn.net/foxdave

This article describes a way to customize a SharePoint menu by customizing the menu for sites such as some portals

The custom menu has its own data source, can be a data table, can be XML, this article describes the use of XML data source as a menu of the declaration definition section, the XML as a file format saved in the Web site in the configuration document library created by itself

The format of the XML menu is formatted as the following format, which has the menu Title Title property, the permissions user group Spgroups property that has the menu, the link URL property of the menu, and the actual application can add more fields.

<SiteMap>
  <sitemapnode title= "My Project" spgroups= "Quality technology center; cost center; branch; 3rd branch; Engineering department; Capital Center; Accounting Center; Operation Center; Internal Audit Center; Financial center; Accounting Center; Test Group; Fund group >
<sitemapnode title= Project Management "Url="/_layouts/sp_mip/pi/pi_basicinfosearchinfo.aspx "spgroups = "Quality Technology center; Capital Center; Accounting center; cost center; Finance Center; branch; 3rd branch; Engineering department; Operation Center; Internal Audit Center; Accounting Center; Test group; Funds group"/>
  </SiteMapNode>
</ Sitemap>
We will provide the webmaster with an interface to define the navigation menu, such as in the site settings, as shown in the figure


Create a new SharePoint solution and add an element to define the Site Settings menu (Customactiongroup and CustomAction nodes). The code is as follows (here is a user-modified password that I added later, not explained here)

<?xml version= "1.0" encoding= "Utf-8"?> <elements xmlns= "http://schemas.microsoft.com/sharepoint/" > < Customactiongroup id= "spmipnavigation" title= "SPMIP navigation" Description = "SPMIP navigation" location = "Microsoft.s 
  Harepoint.sitesettings "Sequence =" 1999 "Imageurl="/_layouts/images/sitesettings_spmipnavigation_48x48.png "> </CustomActionGroup> <customaction id= "Spmiptopnav" groupid= "spmipnavigation" location= "Microsof T.sharepoint.sitesettings "rights=" ManageWeb "sequence=" "title=" Top Navigation "description=" Top Navigation > < UrlAction url= "{siteurl}/_layouts/sp_mip/topnav.aspx"/> </CustomAction> <customaction id= "Spmipleftna V "groupid=" spmipnavigation "location=" Microsoft.SharePoint.SiteSettings "rights=" ManageWeb "sequence=" 201 0 "title=" left navigation "description=" left navigation "> <urlaction url=" {siteurl}/_layouts/sp_mip/leftnav.aspx "/> < /customaction> <custoMaction id= "Spmipchangepassword" groupid= "personalactions" location= "Microsoft.SharePoint.StandardMenu" Se Quence= "title=" "Change Password" description= "Change Password" imageurl= "{siteurl}/_layouts/images/welcome_spmipchangepwd_32x32 . png "> <urlaction url=" javascript:show (); "
 /> </CustomAction> </Elements>
Add the appropriate site assets, such as setting up a picture. Added two pages topnav.aspx and leftnav.aspx. Two pages actually no difference, take Topnav as an example, add a multiline text box, a save button is OK.


Core page Code

<table border= "0" width= "100%" cellspacing= "0" cellpadding= "0" > <wssuc:inputformsection ID= "InputFormSect Ion "title=" Top Navigation "runat=" Server "description=" Top Navigation "> <Template_InputFormControls> &lt
                        ; Wssuc:inputformcontrol id= "Inputformcontrol" runat= "Server" > <Template_Control>
                                <table border= "0" cellpadding= "0" cellspacing= "0" > <tr> &LT;TD align= "Right" style= "padding-bottom:5px" > <a href= "jav
                                        Ascript:topnav_showfullscreen (' <%= txtnavxml.clientid%> ', ' <%= txtnavxmlpop.clientid%> '); " style= "COLOR: #0072bc;"
                                    > <asp:literal id= "LTL" runat= "server" text= "full screen edit"/>
                            </a> </td></tr> <tr> <td>
                                        <asp:textbox id= "Txtnavxml" runat= "Server" wrap= "false" textmode= "MultiLine" rows= "22"
                        Width= "600px"/> </td> </tr> </table> </Template_Control> </wssuc:inputformcon trol> </Template_InputFormControls> </wssuc:InputFormSection> <wssuc:buttons Ection id= "BTS" runat= "Server" showstandardcancelbutton= "false" > <Template_Buttons> &
                Lt;asp:button runat= "Server" class= "Ms-buttonheightwidth" text= "Save" id= "Btnsave" onclick= "Btnsave_onclick"/> <asp:button runat= "Server" class= "Ms-buttonheightwidth" text= "Cancel Id=" btnclose "onclientclick=" TopNav_Close_Clic K (); return false; "/> </Template_Buttons> </wssuc:ButtonSection> </table> <table id= "Tblfullscreen" border= "0" cellpadding= "0" cellspacing= "0" class= "tblpop" > <tr> <td align= "center" valign= "Top" &G
                T
                        <table border= "0" cellpadding= "5" cellspacing= "0" width= "100%" > <tr> <td> <asp:textbox id= "Txtnavxmlpop" runat= "Server" wrap= "false" Textmode= "Multilin E "rows=" width= "99%"/> </td> &lt ;/tr> <tr> <td align= "center" > <
                                A href= "Javascript:topnav_hidefullscreen (' <%= txtnavxml.clientid%> ', ' <%= txtnavxmlpop.clientid%> ');" style= "COLOR: #0072bc;" > <asp:literal id= "LtlclosE "runat=" Server "text=" Off "/> </a> </td> </tr> </table> </td> </tr> </table>
Button background handling Events The thing to do is to read the contents of the XML configuration file and save the user-changed XML definition back to the document library's XML file.

protected void Btnsave_onclick (object sender, EventArgs e)
        {
            try
            {
                Config.save (base). Web, This.txtNavXml.Text, Config.NavType.Top);
                Sputility.redirect ("Settings.aspx", Spredirectflags.relativetolayoutspage, HttpContext.Current);
            }
            catch (Exception Exception)
            {
                spmiptrace.writeerror ("Spmipnavigation", Exception);
            }
        }

        protected void Page_Load (object sender, EventArgs e)
        {
            if (!base. IsPostBack)
            {
                This.txtNavXml.Text = Config.load (base. Web, Config.NavType.Top);
            }
        }
 Class Config {public static string Load (SPWeb Web, Navtype navtype) {string str = NULL;
                try {StreamReader reader;
                SPList settinglist = spmiputility.checksettinglist ("spmipsetting");
                            Switch (navtype) {case Navtype.top: {
                            SPFile topnavsettingfile = settinglist.rootfolder.files["Topnav.xml"]; if (topnavsettingfile.exists) {using (reader = new Streamread ER (Topnavsettingfile.openbinarystream ())) {str = read Er.
                                ReadToEnd ();
                        }} break; } case navtype.left: {SPFile Leftnavsettingfile = settinglist.rootfolder.files["Leftnav.xml"]; if (leftnavsettingfile.exists) {using (reader = new Streamrea Der (Leftnavsettingfile.openbinarystream ())) {str = RE Ader.
                                ReadToEnd ();
                        }} break;
            }} return str; } catch (Exception Exception) {spmiptrace.writeerror ("spmipnavigation", Exception
                );
            return str; }} public static bool Save (SPWEB Web, String filecontent, Navtype navtype) {bool FL
            AG = FALSE;
                try {SPList settinglist = spmiputility.checksettinglist ("spmipsetting"); byte[] bytes = Encoding.UTF8.GeTbytes (filecontent); Web.
                Allowunsafeupdates = true; Switch (navtype) {case NavType.Top:settingList.RootFolder.Fi Les.
                        ADD ("Topnav.xml", Bytes, true);
                    Break
                        Case NAVTYPE.LEFT:SETTINGLIST.ROOTFOLDER.FILES.ADD ("Leftnav.xml", Bytes, true);
                Break
            } flag = true; } catch (Exception Exception) {spmiptrace.writeerror ("spmipnavigation", Exception
            );
        } return flag; } public enum Navtype {Top, left}}
The approximate functionality is complete, and the next section describes how to apply this menu declaration to the master page.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.