Wednesday, August 20, 2008

Creating Custom List Definition in SharePoint Sites



  1. Copy the Custlist folder located in the Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\1033\Site_Template_Name\LISTS directory.
    Rename the new folder as appropriate for the list.
    The following example creates a list to organize shared commuting for employees, and so the folder is named COMMUTING.
    Open the SCHEMA.XML file of the new list folder and create field definitions by adding Field elements within the empty Fields element in the opening MetaData element.
    Definitions added in the MetaData element specify the names and types of fields to use in the list. This example defines seven fields, including Text, Choice, Number, and Note fields. The Choice fields create drop-down lists for making selections.




    Eastgate
    North Park
    South Terrace Center
    Lake Shores




    7am
    8am
    9am
    10am




    4pm
    5pm
    6pm
    7pm





    All fields except the last Note field require that users provide information in order to sign up.
    After you define the fields, you must specify them as view fields in order for them to display in the list. To do this, search for the ViewFields element within the section of SCHEMA.XML that defines the All Items view and add field references, as follows:








    It is required that a custom list definition have a default description. Add a DefaultDescription element within the MetaData element of the SCHEMA.XML file, as follows:
    Use this list to organize shared rides to and from work with others.

    To display the list as an option on the Create Page, you must specify the new list type within the ListTemplates element of the ONET.XML file for the site definition, located at Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\1033\[Site_Template_Name]\XML. To do this, find the ListTemplates element and add a ListTemplate element, as follows:


    The example specifies both the displayed and internal names, as well as an image and description to use on the Create Page. Since the list definition is based on a the Generic List type, the value of its BaseType attribute is set to 0.
    Important The Name attribute must be set to the exact name of the new list folder. To identify the list, assign a numerical ID that is not being used elsewhere and that is less than 1000 to the Type attribute.
    The example sets the OnQuickLaunch attribute to FALSE. This attribute specifies whether the option to display the list in the Quick Launch area appears selected by default on the page for creating an instance of the list.
    The SecurityBits attribute specifies permissions for a list, where the first bit represents Read access and the second bit represents Write access. The bit for Read access contains one of two possible values: 1 allows all users Read access to all items, and 2 allows users Read access only to items they create. The bit for Write access contains one of three possible values: 1 allows all users to modify all items, 2 allows users to modify only items they create, and 4 prevents users from modifying the list. This example sets the security bits to 12, which prevents users from modifying the items of other users.
    The new list list definition now appears on the Create Page and users can add lists to the Microsoft SharePoint site using the new definition.

Tuesday, April 22, 2008

Implementation of People Picker Control in Custom Web Parts

1. Declaration and assigning properties to People Picker.
This section discusses about the declaration and assigning properties to a people picker control. The people picker is enabled through a class called PeopleEditor. The declaration of PeopleEditor is as follows:

//Class definitions to be included for enhancing People Picker
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Portal.UserProfiles;
using Microsoft.SharePoint.Portal.Topology;
using Microsoft.SharePoint.Portal;
//Declaring PeopleEditor object
PeopleEditor ctrlpplPicker = new PeopleEditor ();
//Defining properties of the PeopleEditor
ctrlpplPicker.AutoPostBack = false;
ctrlpplPicker.PlaceButtonsUnderEntityEditor = true;
ctrlpplPicker.ID = "pplEditor";
ctrlpplPicker.AllowEmpty = false;
ctrlpplPicker.SelectionSet = "User, DL, SecGroup, SPGroup";
ctrlpplPicker.MultiSelect = true;
ctrlpplPicker.MaximumEntities = 5;
The AutoPostBack property makes a page refresh on addition of value. It is assigned to false in order to avoid page refreshing.
The PlaceButtonsUnderEntityEditor property decides the location of the Names and Browse buttons of the people picker. If you set it to true, the buttons are placed at the bottom right corner of the account name text box, otherwise to the right of it.
The AllowEmpty property lets you define if the user is required to fill in a value in the people picker.
The SelectionSet property allows you to define the set of users and groups the people picker can choose from. This set can consist of users, Active Directory distribution lists, Active Directory security groups, and SharePoint groups.
The MultiSelect property lets you define if a user is allowed to specify multiple user accounts.
The MaximumEntities property restricts the maximum number of people or groups to be added to the control.


2. Obtaining details of the entries added in the people picker
Once the people picker control is added in a webpart, the next task would be to resolve the entries made, obtain the details of the entries (like display name, email ID) and update the list. The below function explains about obtaining details of the entries made in the people picker.
// pplInfo is a string array which is used to hold display name and the email ID of the entries.
//Declaring pplInfo
String[] pplInfo = new String[2];
pplInfo[0] = String.Empty;
pplInfo[1] = String.Empty;
// objEntity is an object of Picker Entity class which stores the individual entry (people or group) added in the people picker control. This object is required to obtain the details of the people or group added in the control. objPplEditor.ResolvedEntities is a property of Picker Entity which resolves the entries made in the people picker control.
//The below for loop gets the count of number of entries made in the people picker. For every entry made, pplInfo [0] stores DisplayName and pplInfo [1] stores email ID.
for(int i = 0; i < objentity =" (PickerEntity)">


3. Updating people picker control values to a list item

Now we have the display name and the email ID of the entries made in people picker control in a string array pplInfo (pplInfo [0] stores Display Name and pplInfo [1] stores email ID). These values can be used to store display name and email ID in the list item.

//Open the share point site which contains the list in which the entities of the people picker is to be updated.
SPWeb myweb = new SPSite(siteName).OpenWeb();
//Gets the list name from the share point site
SPList mylist = myweb.Lists[listName];
// ‘newitem’ is a SPListItem object which points to new list item to be added to the list.
SPListItem newitem = mylist.Items.Add();
//The display name and Email ID of the values entered in people picker control are updated to the list as shown below. Update () is the function which is used to update the list item.
newitem[columnName_DisplayName] = pplInfo[0];//Display name
newitem[columnName_EmailID] = pplInfo[1];//Email ID
newitem.Update( );



4. Clearing existing entities in the control
Once the control values are updated to the list we need to clear the control. The people editor control has property Entities.Clear( ) which clears the entries made in people picker.
ctrlpplPicker.Entities.Clear();



5. Populating values to control from the list
There can be a requirement where we need to obtain the details of a list item from the sharepoint list and populate the obtained values to corresponding controls for viewing or editing. For example, in the case of meeting details, the attendees will be populated to people picker control, meeting name to textbox control, etc. The below section explains how the values are obtained from the list and populated to the control.
//Holds the display names on getting the values from the list. Every display name is separated by semi-colon(;)
string pplNames_List= "";
pplNames_List= master[columnName_DisplayName].ToString();
//Holds the display name on resolving entities pplNames_List separated by semi-colon
string[] pplNames;
pplNames = pplNames_List.Split(';');
//Arraylist which holds the complete list of names to be added to the control
System.Collections.ArrayList pplList = new System.Collections.ArrayList();
//Store all the values in pplNames in PickEntity object entity and store the entities to pplList.
for (int pplCounter = 0; pplCounter < entity =" new" key =" pplNames[pplCounter];">