Displaying user field in site definition

Background

This is one of the most interesting learning point for me to add a user field in site definition. Because while doing so I understood a lot of things about site definition and how it works.

Okay, the main point is to add user field in site definition, so let’s get started.

For this we have to create a site definition and then a list definition and finally a user field.

 

1. Creating empty solution

Project creation

Project creation

2. Adding site definition project

Site Definition project creation

Site Definition project creation

Solution explorer
Solution explorer

3. Adding list definition

Adding list definition

Adding list definition

4. List Definition settings

List Definition settings

List Definition settings

5. Changing the list definition (elements.xml file)

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List Definition project item, an error will occur when the project is run. -->
<ListTemplate
Name="ListWithUserField"
Type="10001"
BaseType="0"
AllowDeletion="FALSE"
Hidden="TRUE"
DisableAttachments="TRUE"
OnQuickLaunch="TRUE"
SecurityBits="11"
Sequence="410"
DisplayName="ListWithUserField"
Description="My List Definition"
Image="/_layouts/images/itgen.png"/>
</Elements>

6. Changing the list schema in schema.xml file

<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="ListWithUserField" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/SiteDefinitionDemo-ListWithUserField" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
<MetaData>
<ContentTypes>
<ContentTypeRef ID="0x01">
<Folder TargetName="Item" />
</ContentTypeRef>
<ContentTypeRef ID="0x0120" />
</ContentTypes>
<Fields>
<Field ID="{82642ec8-ef9b-478f-acf9-31f7d45fbc31}"
Name="LinkTitle" Hidden="FALSE"
SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="LinkTitle" Type="Text" />
<Field ID="{bc91a437-52e7-49e1-8c4e-4698904b2b6d}"
Name="LinkTitleNoMenu" Hidden="TRUE"
SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="LinkTitleNoMenu" Type="Text" />
<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}"
Name="Title" SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="Title" Type="Text"
AllowDeletion="FALSE"
Description="Title" DisplayName="Title"
ShowInDisplayForm="TRUE"
ShowInEditForm="TRUE"
ShowInNewForm="TRUE"
EnforceUniqueValues="TRUE"
ShowInViewForms="TRUE"
ListItemMenu="TRUE"
Required="TRUE"
Sealed="TRUE" />
<Field Name="CustomUserField"
ID="{F2A7CBA5-2134-417F-BAEA-C031EA6D99C0}"
StaticName="CustomUserField"
DisplayName="CustomUserField"
Description="Responsible"
AllowDeletion="FALSE"
ShowInViewForms="TRUE"
ShowInDisplayForm="TRUE"
ShowInEditForm="TRUE"
ShowInNewForm="TRUE"
Sealed="TRUE"
Required="TRUE"
Mult="TRUE"
List="UserInfo"
ShowField="ImnName"
UserSelectionMode="PeopleAndGroups"
UserSelectionScope="0"
Type="UserMulti" />
</Fields>
<Views>
<View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ViewFields>
<FieldRef Name="LinkTitle"></FieldRef>
<FieldRef Name="CustomUserField"></FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
</ParameterBindings>
</View>
<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pagesviewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ViewFields>
<FieldRef Name="LinkTitle"></FieldRef>
<FieldRef Name="CustomUserField"></FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="ID"></FieldRef>
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
</ParameterBindings>
</View>
</Views>
<Forms>
<Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pagesform.aspx" WebPartZoneID="Main" />
<Form Type="EditForm" Url="EditForm.aspx" SetupPath="pagesform.aspx" WebPartZoneID="Main" />
<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pagesform.aspx" WebPartZoneID="Main" />
</Forms>
</MetaData>
</List>

7. Amending the one.xml (site schema)

<Lists>
<List Title="ListWithUserField"
FeatureId="93cb10b7-bd60-432b-9608-9916fba9497a"
Url="Lists/ListWithUserField"
QuickLaunchUrl="Lists/ListWithUserField/AllItems.aspx"
Description="ListWithUserField" Type="10001" />
</Lists>

8. Getting the feature ID

Feature ID

Feature ID

9. Deploy the project

10. Go to central administration and click on “Create site collections”

Central administration

Central administration

11. Specify site collection details

 

Creating site collection

Creating site collection

12. Site created successfully

Site created successfully

Site created successfully

13. Open the site

Site default page

Site default page

14. Click on “All Site Content” and click on the List name that we have just created

15. Then click on “Add new item” and you can see the user field that we have created

Adding data

Adding data

16. Displaying added data

Displaying data

Displaying data

That’s it, and we are done with it.

Hope this will help you guys.

Posted in Sharepoint Tagged with: ,