Sunday, November 16, 2008

Creating SP Site Feature

This post would make one understand in simple 10 steps how to create and deploy a SharePoint Site Feature (in this case a page).

This is simple but very useful in case of you already have an existing portal and want to deploy a new page / item (could be anything) when there is no provision to modify ONET.xml file.

Step 1 # Create a folder in the web project (you can create any where... using Visual Studio is not a mandate here) with the name of the Site Feature you want to deploy to the SP Site / Web. NewFeaturePage in this example. It is preferable to have no space in the Feature name but thats not mandatory. Best practices suggests to have 'u20' (html encoded) to replace spaces in the feature name.
Step 2 # Add a (new) XML File to the folder and name it as Elements.xml
Step 3 # Create a new .aspx page to the folder and name it as NewFeaturePage.aspx (in this example)
Step 4 # Add a (new) XML File to the folder and name it as Feature.xml
Step 5 # From VS Designer, TOOLS > CREATE GUID create a new GUID. Use this new GUID in the Feature.xml as shown below for Feature ID.

the contents of Elements.xml can be as simple as below...
------------------------------------------------------------------------
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="NewFeaturePage" Path="" Url="" >
<File Url="NewFeaturePage.aspx" Type="Ghostable" IgnoreIfAlreadyExists="FALSE" />
</Module>
</Elements>
------------------------------------------------------------------------
the contents of Feature.xml would be as below...
------------------------------------------------------------------------
<Feature
Id="{USE THE NEW GUID HERE}"
Title="New Feature"
Description="New Feature"
Scope="Web"
xmlns="http://schemas.microsoft.com/sharepoint/"
Hidden="False"
>
<ElementManifests>
<ElementManifest Location="Elements.xml" />
</ElementManifests>
</Feature>
------------------------------------------------------------------------

Step # 6 Copy the NewFeature folder from your project or local folder) to the following location on the SharePoint Server box. If you followed Step 1 - 6 by log in to the SP Server box, copy the folder locally.

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\

SKIP THE BELOW STEP IF YOU ARE ON SP SERVER BOX ALREADY
Step # 7 Logon to SP Server box.

Step # 8 If you have map path to stsadm run the below command directly. Else, map to the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\

stsadm -o installfeature –filename NewFeature\Feature.xml

This would install the feature

Step # 9 C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\

stsadm -o activatefeature –filename NewFeature\Feature.xml -url http://ServerName/Sitecollection

This would activate the feature.

and now one should be able to access the NewFeaturePage.aspx page from http://ServerName/NewFeaturePage.aspx (based on where you deploy as part of your Elements file File URL Property).

No comments: