How to develop and deploy feature instances

Source: Internet
Author: User
Features is a new function available out of the box in Moss 2007. features are stored in the following path of the Sharepoint Server: C: "Program Files" common files "Microsoft shared" Web Server Extensions "12" template "features. Each featrue has its own subdirectory under this path. Under each feature subdirectory, a file named feature. XML is found, which stores metadata about featrue.
Next I will use feature to implement a small function. Add a custom menu in "website operations". First, use vs2005 to create a helloworld class library project, and then add the folder helloworld, add feature to the folder. the XML file code is as follows:


<Feature id = "feature" Title = "Hello World feature" Description = "this is my first feature" Scope = "Web" hidden = "false" imageurl = "TPG \ canteen.gif "receiverassembly =" helloworld, version = 1.0.0.0, culture = neutral, publickeytoken = f4377ffb300b91ce "receiverclass =" helloworld. featurereceiver "xmlns =" http://schemas.microsoft.com/sharepoint/ ">
<Elementmanifests>
<Elementmanifest location = "elements. xml"/>
</Elementmanifests>
</Feature>
The following describes the metadata information contained in the featrue element.
ID: a guid used to uniquely identify the feature, which can be obtained using the guid generation tool;
Scope: The value can be web or site. It indicates whether the feature is applied to the entire site collection or only for a separate subsite. If scope = "Web", activate it under [website operations-website settings-website management-Website Functions, if scope = "Site", activate it under [website operations-website settings-website management-website set function.
Hidden: The value can be true or false. This setting specifies whether the feature is displayed on the site feature page.
Defaultresourcefile: name of the resource file. Feature depends on it to provide additional configuration information.
<Elementmanifests> element: This element contains the location of another XML file, and the content of <elemnets> in this file is implemented by feature.
Then we add the elements. xml file with the following code:


<Elements xmlns = "http://schemas.microsoft.com/sharepoint/">
<Customaction id = "siteactionstoolbar" groupid = "siteactions" location = "Microsoft. sharepoint. standardmenu "sequence =" 100 "Title =" Hello World "Description =" use feature to customize Menus "imageurl =" _ layouts/images/crtsite.gif ">
<Urlaction url = "http://msdn.microsoft.com"/>
</Customaction>
</Elements>
This is our custom menu item.
After adding a class file featurereceiver. CS, the Code is as follows:


Using system;
Using Microsoft. SharePoint;
Namespace helloworld
{
Public class featurereceiver: spfeaturereceiver
{
Public override void featureinstalled (spfeaturereceiverproperties properties ){}
Public override void featureuninstalling (spfeaturereceiverproperties properties ){}
Public override void featureactivated (spfeaturereceiverproperties properties)
{
Spweb site = (spweb) properties. feature. parent;
Site. properties ["originaltitle"] = site. title;
Site. properties. Update ();
Site. Title = "Hello World modify ";
Site. Update ();
}

Public override void featuredeactivating (spfeaturereceiverproperties properties)
{
Spweb site = (spweb) properties. feature. parent;
Site. Title = site. properties ["originaltitle"];
Site. Update ();
}
}
}
The spfeaturereceiver class defines that when the Web part feature is installed, activated, deactivated, or uninstalled, moss triggers these events. here we need to set the receiverassembly and receiverclass attributes in feature. xml. These attributes point to the Managed class of a function receiver. Publickeytoken is the key of helloworld, which can be obtained by using "Sn-T helloworld" in the vs2005 command line.

Basically, our task is complete. Now we are about to start the deployment. You need to follow these steps:
1. add the helloworl folder (including feature. XML and elements. to the c: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ template \ features folder.
2. stsadm-O installfeature-filename helloworld \ feature. XML-Force


3. Use "gacutil-If Assembly name" to register helloworld. DLL to GAC


4. Restart IIS: iisreset
Now we can go to the website set function to check whether the feature can be activated. When activated, the code in featureactivated will be executed.


Of course, we can use a batch process to complete this deployment process. Note the path changes:
@ Set templatedir = "C: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ template"
@ Set stsadm = "C: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ bin \ stsadm"
@ Set gacutil = "D: \ Program Files \ Microsoft Visual Studio 8 \ SDK \ V2.0 \ bin \ gacutil.exe"
Echo installing helloworld. dll in GAC
% Gacutil %-if bin \ debug \ helloworld. dll
Echo copying files to template directory
Xcopy/e/y template \ * % templatedir %
Echo installing feature
% Stsadm %-O installfeature-filename helloworld \ feature. XML-Force
Iisreset
Rem cscript c: \ windows \ system32 \ iisapp. vbs/a "sharepointdefaultapppool"/R
The following figure shows the final implementation result.



Source Code: "style =" color: # ff0000 "href =" http://files.cnblogs.com/lygx/HelloWorld.rar "> http://files.cnblogs.com/lygx/HelloWorld.rar
"This article is the result of my work. If you have reprinted it, please indicate the source! Thank you for your cooperation ."

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.