Home > Lists, Sharepoint2010 > List Definition using sandbox in sharepoint 2010

List Definition using sandbox in sharepoint 2010

I wanted to create list definition in 2010, like every developer the first thing which came up in my mind was Google.

This are two thread which came up

http://msdn.microsoft.com/en-us/library/ff728096.aspx

http://johanolivier.blogspot.com/2010/05/developing-list-definition-in.html

But there were drawback of these approaches

1) They were deployed as farm solution, I wanted sandbox solution

2) They require content type, so when you create list definition a content type gets created in your Site, I wanted columns to come from metadata not from content type.

So after doing good amount of RND I found how to create list definition using sandbox solution.

I will explain step by step how to do it

Open Visual studio and select sharepoint tab, select 2010 and using Empty SharePoint project template create a project.

Enter the site name where you want to deploy the list definition; we will deploy it as sandbox solution.

Click finish, project will be created.

Now click on Add new item to project. Select list definition, provide the name and click on Add.

When you will click on Add below window will come up, provide name of list definition[this name will come up as list definition name in your SharePoint site], In this case we are going to create custom list so we will select custom list as list definition type.

Click Finish, VS will add features, package, list instance automatically; your project should look like below screen shot.

Open Schema.xml file under SampleListDef level.

If you open content types section you will see this

Remove ContentTypeRef ID=”0x01” section, your content type structure will look like this

Now Add new contentType [don’t add ContentTypeRef] provide it with ID and all the attributes.

ID should be given as follows

0x0100-Guid

Now we need to add Custom columns which we need to add to our SampleList in FieldRefs section.

Each fieldRef should have ID and Name

After Adding fieldRef in content type , we need to Add those fields with additional attributes in <Fields></Fields Section.

Now we need to add Custom columns which we need to add to our SampleList in FieldRefs section.

Each fieldRef should have ID and Name

After Adding fieldRef in content type , we need to Add those fields with additional attributes in <Fields></Fields Section.

Sample Fields

<Field Type=”Text” DisplayName=”Country Code” Required=”FALSE” EnforceUniqueValues=”FALSE” Indexed=”FALSE” MaxLength=”255″ ID=”{26da1ec9-b18b-4b9e-9c41-ed060038de6e}” StaticName=”Country_Code” Name=”Country_Code” ColName=”nvarchar4″ RowOrdinal=”0″ />

<Field Type=”Number” DisplayName=”SortOrder” Required=”FALSE” EnforceUniqueValues=”FALSE” Indexed=”FALSE” ID=”{8f35d3fe-0c20-4b5d-b970-d1630a0c5519}” StaticName=”SortOrder” Name=”SortOrder” ColName=”float1″ RowOrdinal=”0″ />

Note : ID of this field and ID of fieldref in contenttype should be same. Your shema.xml should look like this.

Now Add Those fields in Viewfields section as shown below

That’s it , just right click on project and then deploy it.

Once it is deployed you will be able to see sampleListDef-ListInstance 1, List instance created in your site.There is no need to reset IIS as this is sandbox solution.

This name is coming from

Let go and check how our list looks

looks good..what say..lets click add new

i,m impressed with that dialoge box, lets save the data

its working, now the last and most important..lets see if List definition was created.

Ahh.it there…

let me know if you have any questions.

Advertisements
Categories: Lists, Sharepoint2010
  1. May 2, 2011 at 9:06 am

    Is there any way to have data from SQL server to the List definition during development?

  2. Josey
    May 13, 2011 at 2:46 pm

    Nice post. Very informative.

    One question though… Can you assign a specific GUID to a custom content type as well as a custom site column programmatically as a sandboxed solution? I tried to deploy a CT and site column through a feature activation to multiple site collections but I’m running into the problem of GUIDs not matching. So when I create a site template of site A and deploy it to site B, its just duplicates the content type (two CT with the same name but different GUID).

    Thanks.

  3. February 19, 2013 at 4:01 pm

    I really blog too and I’m creating a little something very
    similar to this excellent blog, “List Definition using sandbox in sharepoint 2010 sharepoint 2010”.
    Do you really mind in the event I personallyincorporate a
    little of your own suggestions? Thanks ,Katie

  4. Jain
    June 14, 2013 at 7:31 am

    Hi there i am getting a feature activated error

  1. March 15, 2012 at 1:41 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: