This example shows how to add a link to Site Actions menu. We are going to use mapped folders to deploy an image and an application page to which the new link will point. In order to customize the menu we are going to use CustomAction element:
<CustomAction Id="CustomActionID" Description="Custom Action Description" Title=" Custom Action Title" GroupId="SiteActions" Location="Microsoft.SharePoint.StandardMenu" ImageUrl="/_layouts/Images/SPCustomAction/MyIco.bmp" Sequence="10">
GroupId and Location attributes determine where the custom action is displayed. Since we want to add a link to SiteActions menu we are using SiteActions GroupId. You can find the list of default custom action locations and IDs over at MSDN.
We are going to start with an Empty SharePoint project (name the project SPCustomAction). Select “Deploy as a farm solution” in the project wizard. Reason for using the farm solution is because we want to deploy an image as well as application page and you can’t do that with sandboxed solutions.
To add a mapped folder to the project, right click the project name and select Add -> SharePoint 'Images" mapped folder. Once mapped folder is in your project it works same as any other regular folder. You can right click the folder and add either a new image (BMP) or an existing one to the project. I named my BMP file MyImage.bmp. If you use named your file with differently, make sure the name matches the one you specify in the ImageUrl attribute below.
Next we need to add an application page – right click the project name and select Add -> New Item . From the New Item dialog, select the Application Page template and click add (name the page MyAppPage.aspx). You will notice that the Layouts mapped folder is added to the project and it contains the application page. If you want to use an existing ASPX file you could add a Layouts mapped folder first and then add the ASPX file to that folder.
Now we can start with the CustomAction. We are going to use an Empty Element project item template. Open Add New Item dialog and add an Empty Element template to the project. Elements.xml file should be opened by default. Paste the following XML to the Elements.xml file:
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <CustomAction Id="MyCustomAction" Description="This is my custom action." Title="Open Application Page" GroupId="SiteActions" Location="Microsoft.SharePoint.StandardMenu" ImageUrl="/_layouts/Images/SPCustomAction/MyImage.bmp" Sequence="10"> <UrlAction Url="~site/_layouts/SPCustomAction/MyAppPage.aspx"/> </CustomAction> </Elements>
That’s all you need to do in order to create a new custom action. Deploy the project (or press F5) and navigate to your SharePoint site. If you open the Site Actions menu there should be a new link with custom image. When you click the link it should open the MyAppPage.aspx application page we added to the project.