IAddtoGallery interface

Defines a property that allows a Web Part to add menu items to the Add Web Parts gallery tool pane.

Namespace:  Microsoft.SharePoint.WebPartPages
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public interface IAddtoGallery

The following code example shows a Web Part class that implements the IAddtoGallery interface and sets the GalleryOptions property to define two menu commands that extend the menu of the Add Web Parts tool pane. For information on the format of the XML fragment use to define menu commands, see the GalleryOptions property.

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

namespace ExampleWebPartLibrary


    // Derive from WebPart base class and implement the IAddToGallery interface.
    public class IAddToGalleryWebPart : 
        // Create and return the XML fragment to define two menu commands.
        Public string GalleryOptions
                string mytemplate;
                mytemplate = "";
                mytemplate += "<?xml version=\"1.0\"?>";
                mytemplate += "<GalleryOptions>";
                mytemplate += "<Option ID=\"{CAEAE2BB-56F8-426f-A279-
                mytemplate += "<OptionName>Command 1</OptionName>";
                mytemplate += "<LinkValue>javascript:alert('Command 1 
                    was clicked.');</LinkValue>";
                mytemplate += "</Option>";
                mytemplate += "<Option ID=\"{3A570BED-D135-4220-8460-
                mytemplate += "<OptionName>Command 2</OptionName>";
                mytemplate += "<LinkValue>javascript:alert('Command 2 
                    was clicked.');</LinkValue>";
                mytemplate += "</Option>";
                mytemplate += "</GalleryOptions>";
                return mytemplate;

        /// <summary>
        /// Render this Web Part to the output parameter specified.
        /// </summary>
        /// <param name="output"> The HTML writer to write out to </param>
        protected override void RenderWebPart(HtmlTextWriter output)
            // Code for rendering Web Part.