In this article we will see how we can develop a simple future for SharePoint.
Before starting the development, make sure that the following tools are installed.
1. Visual studio extension for windows SharePoint services:
Note: You can refer the link
http://www.allaboutmoss.com/index.php/2010/03/22/install-visual-studio-2005-extensions-in-windows-xp-or-vista/ for installing Visual studio extension in Windows XP
2. WSP Builder: http://www.codeplex.com/wspbuilder
Let’s get started. Fire up visual studio
Click File -> New -> Project
Choose the language (I am choosing c# for this tutorial) and select WSP Builder Project . Enter a project name and click OK.
Add the reference for sharepoint DLL in your project.
Right click the project click on property and choose signing create a strong key and click OK without password. Then save the project.
Add feature template in this project by Right clicking the project -> Add -> New Item
Choose WSPbuilder, select Feature with receiver and give the name of feature. Click OK
Then enter the feature settings (I am choosing web as scope)
Scope specifies the scope in which the Feature can be activated and contains one of the following values: Farm (farm), WebApplication (Web application), Site (site collection), Web (Web site).
Open the simplefeature.cs file
We have to comment below code from the FeatureActivated,FeatureDeactivating, FeatureInstalled and FeatureUninstalling method.
throw new Exception(“The method or operation is not implemented.”);[/sourcecode]
Add the following code in FeatureActivated method. This code is to create a Custom List in the site while activating feature.
SPSite site = SPContext.Current.Site;
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPListTemplateCollection customListTemplates = site.GetCustomListTemplates(web);
SPListTemplate listTemplate = web.ListTemplates["Custom List"];
web.Lists.Add(“Mylist”, “A custom list created by feature”, listTemplate);
web.AllowUnsafeUpdates = false;[/sourcecode]
That’s it. Build your project and make sure there are no errors.
Next step is to build WSP for this.Right click the Solution -> WSP Builder -> Build WSP.
Now you will see a new file named simplefeature.wsp in your project folder.
Deploy and Activate this feature in server
- Copy the WSP to your SharePoint server
- Open command prompt and navigate to the folder Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
- run stsadm -o addsolution -filename “G:\simplefeature.wsp”
- Open central administration -> click operations
- Click Solutions under Global configurations
- Locate the newly added web part (simplefeature.wsp) and click to open its solution property page.
- Click solution deploy link and click OK in the resulting page.
- Browse our sharepoint site
- Go to Site Action-> Site settings -> Site feature
- Activate Simplefeature
Now you can see a custom list named ‘Mylist’ is created in your site.