Requirement: Create a new Link list with pre-populated list items as a feature based solution. Steps: 1. Create a New Empty SharePoint Project, Give it a name, I've named it as Crescent.Portal.DashboardLinks 2. In the next dialog box, Select either Farm solution or Sandboxed solution whichever applicable to your requirements. I've selected "Deploy as a Farm Solution" 3. Right click the Project in visual studio solution explorer >> Add >> New Item >> List Instance 4. Enter the List Instance settings: Link List Name, List to Instantiate, URL. Click Finish. 5. Now our project will look like the below screen. Look at the "FeatureId" attribute. This is the Feature ID of the Link List feature. In case, If you want to create a List instance for your own List definition, You can use the Feature ID of the particular List. (You can just get into 14 Hive, Templates and pick the relevant feature folder's Feature.xml file to get the feature Id) 6. Rename the Feature from "Feature1" to "DashboardLinks" in solution explorer. Get into the Feature designer (Right-click the "DashboardLinks" and choose "View Designer"), Give it a meaning full title (Here I've given "Dashboard Links Feature")
Desired to gain proficiency on SharePoint? Explore the blog post on the "SharePoint Training" course to become a pro in SharePoint.
that will appear on the site features page. Add the DashboardLinks ListInstance Element to the feature. 7. Our requirement is to Pre-populate the Dashboard Links list. So, Let’s add the <Data> element with values to theElements.xml as below: <?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <ListInstance Title="Dashboard Links" OnQuickLaunch="TRUE" TemplateType="103" FeatureId="00bfea71-2062-426c-90bf-714c59600103" Url="Lists/DashboardLinks" Description=""> <Data> <Rows> <Row> <Field Name="URL">http://Crescent.SharePoint.com/sites/PMO/Dashboard, PMO Dashboard</Field> <Field Name="Comments">PMO Dashboard Link</Field> </Row> <Row> <Field Name="URL">http://Crescent.SharePoint.com/sites/functional/Dashboard, Functional Dashboard</Field> <Field Name="Comments">Functional Dashboard Link</Field> </Row> <Row> <Field Name="URL">http://Crescent.SharePoint.com/sites/operations/Dashboard, Operational Dashboard</Field> <Field Name="Comments">Operations Dashboard Link</Field> </Row> </Rows> </Data> </ListInstance> </Elements> 8. Build and deploy the Project (Just right click the Project in visual studio, choose Build and then choose Deploy) 9. Verify the feature is activated by going to Site actions >> Site settings >> Manage Site features (Under Site actions tab) 10. See it in action! You might be interested in: Track farm changes Track changes and get email when SharePoint farm settings change Add Feature Event Receivers Feature event receivers are methods that execute when one of the following feature-related events occurs in SharePoint:
This walkthrough demonstrates how to add an event receiver to a feature in a SharePoint project. It demonstrates the following tasks:
Note |
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements |
Prerequisites You need the following components to complete this walkthrough:
Creating a Feature Event Receiver Project First, create a project to contain the feature event receiver. To create a project with a feature event receiver
This project type is for feature event receivers because there is no project template for them.
For more information about sandboxed solutions versus farm solutions, see Sandboxed Solution Considerations. Adding an Event Receiver to the Feature Next, add an event receiver to the feature and add code that executes when the feature is deactivated.
To add an event receiver to the features
Notice that a feature named Feature1 appears under the Features node.
This adds a code file under Feature1. In this case, it is named either Feature1.EventReceiver.cs or Feature1.EventReceiver.vb, depending on your project's development language.
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { try { // Get reference to SharePoint site. SPSite site = new SPSite("http://localhost"); SPWeb web = site.OpenWeb("/"); // Get reference to Announcements list. SPList announcementsList = web.Lists["Announcements"]; // Add new announcement to Announcements list. SPListItem oListItem = announcementsList.Items.Add(); oListItem["Title"] = "Deactivated Feature: " + properties.Definition.DisplayName; oListItem["Body"] = properties.Definition.DisplayName + " was deactivated on: " + DateTime.Now.ToString(); oListItem.Update(); } catch (Exception e) { Console.WriteLine("Error: " + e.ToString()); } } Testing the Feature Event Receiver Next, deactivate the feature to test whether the FeatureDeactivating method outputs an announcement to the SharePoint Announcements list. To test the feature event receiver
Setting this property prevents the feature from activating in SharePoint and lets you debug feature event receivers. For more information, see Debugging SharePoint Solutions.
Notice that an announcement appears in the Announcements list after the feature is deactivated. SharePoint Features can be scoped to the Farm, Web Application, Site Collection, and Web Site level depending on the purpose of the feature. The Feature scope is determined by the setting of the Scope attribute in the Feature element defined in the feature.xml file. A sample Feature element tag is given below: <Feature Id="F62C96CF-79FD-44be-8882-E9BFBD199184" Title="Feature Title" Description="Feature Description" Version="1.0.0.0" Scope="Site" Hidden="false"> </Feature> Web Site scoped Feature (Scope="Web"): A Web Site scoped Feature is one that can be activated only at the individual Web site level. List templates, list instances, custom actions, event receivers, etc are some common elements for web site scoped features. Web Site scoped features can be activated by using one of the following two methods:
Site Collection scoped Feature (Scope="Site"): A Site Collection scoped Feature is one that can be activated at the site collection level and contains items that apply to the site collection as a whole (for example, content types that are shared across the site collection), as well as items that can be activated per site (for example, list instances, etc). Site Collection scoped features can be activated by using one of the following two methods:
Web Application scoped Feature (Scope="WebApplication"): A Web Application scoped Feature is one that can be activated at the web application level and contains items like administrative web application links, delegate control registrations, feature/site template association, document form registrations, etc. A farm Feature can contain, for example, links to /_layouts pages and files, /_admin pages, and other elements. Web Application scoped features can be activated by using one of the following two methods:
Farm scoped Feature (Scope="Farm"): A Farm scoped Feature can be activated at the server farm level. A farm Feature contains a number of elements that are critical for implementing applications and logic anywhere within a deployment. A farm Feature can contain, for example, links to /_layouts pages and files, /_admin pages, and other elements. Farm scoped features can be activated by using one of the following two methods:
Note: The farm scoped feature is activated automatically once it is installed on the server farm. SharePoint Element Types for Features: The following table describes various element types for Features and shows their possible settings for scope.
Element | Description | Scope |
Content-Type | Contains a schema definition you can reuse and apply to multiple list definitions. | Site |
Content-Type Binding | Content-type binding enables you to provision a content type on a list defined in the Onet.xml schema. Lists defined in the Onet.xml schema cannot be modified directly. | Site |
Control | A delegate control contains a registration for a well-known control installed on a Web page. This lets you replace existing controls, such as the Windows SharePoint Services search control, with another control. | Farm, WebApplication, Site, Web |
Custom Action | You can define the following kinds of custom actions:
|
Farm, WebApplication, Site, Web |
Custom Action Group | Defines a group of custom actions. | Farm, WebApplication,Site, Web |
Document Converter | Contains the definition of a document converter. A document converter is a custom executable file that takes a document of one file type, and generates a copy of that file in another file type. | WebApplication |
Feature/Site Template Association | Binds a Feature to a site definition configuration so that created sites are provisioned with the Feature. | Farm, WebApplication,Site |
Field | Contains a field definition that can be reused among multiple lists. | Site |
Hide Custom Action | Hides a custom action that has been added through another custom action. | Farm, WebApplication,Site, Web |
List Instance | Provisions a SharePoint site with a specific list of data. | Site, Web |
List Template | Contains a list definition or template, which defines a list that can be provisioned in a SharePoint site. | Site, Web |
Module | Contains a set of files with which to provision sites. | Site, Web |
Receiver | Contains an item event receiver registration. | Web |
Workflow | Contains the definition for a workflow in a list. | Site |
For an in-depth understanding of SharePoint click on
You liked the article?
Like : 0
Vote for difficulty
Current difficulty (Avg): Medium
1/6
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.
Stay Updated
Get stories of change makers and innovators from the startup ecosystem in your inbox