【转】http://www.johnchapman.name/sharepoint-2010-create-a-simple-custom-action-using-visual-studio-2010/
Visual Studio 2010 has added a multitude of new features to make custom development on SharePoint 2010 much simpler that it was previously. Though Visual Studio 2010 does not include a simple wizard or other simpler process for creating Custom Actions, we can still take advantage of the simple packaging, debugging, and deployment features available for SharePoint 2010. In addition, Custom Actions point to custom application pages or other custom functions contained in the same Visual Studio solution.
You will need a development environment with SharePoint Foundation 2010 or SharePoint Server 2010 as well as Visual Studio 2010. Developing for SharePoint 2010 in Visual Studio 2010 requires you to run them both on the same machine (not your production server however). For information on setting up your development environment, see http://msdn.microsoft.com/en-us/library/ee554869.aspx.
To get started:
Now you have an empty Elements.xml file to create your Custom Action with:
1 | <? xml version = "1.0" encoding = "utf-8" ?> |
For this example, paste the following in place of the existing content:
1 | <? xml version = "1.0" encoding = "utf-8" ?> |
3 |
< CustomAction Id = "SiteActionsToolbar" GroupId = "SiteActions" Location = "Microsoft.SharePoint.StandardMenu" Sequence = "1000" Title = "Bing" > |
This simple Custom Action will add a link to Bing on the Site Actions menu. Now deploy your solution to SharePoint to test it:
- Right click the Solution Name in the Solution Explorer and select Deploy:
- Visual Studio will indicate when it has completed building and deploying the solution to your local SharePoint site:
- Now navigate to your SharePoint site in a web browser. Under the Site Actions you will now have a link to Bing:
That is how a simple Custom Action is created. In upcoming articles I will demonstrate how to add Custom Actions to different parts of the SharePoint Interface, such as the Ribbon and Site Settings.