Showing posts with label list definition. Show all posts
Showing posts with label list definition. Show all posts

Sunday 19 May 2013

Creating related lists for SP Hosted Apps using VS2012

Problem:  SharePoint Hosted apps need to use their own site collection (app site collection) to hold list data.  In this post I look at setting up 2 lists that are related.  To clarify what I am trying to achieve I have created an Entity Relationship Diagram (ERD) below.

Initial Hypothesis:  Provisioning fields, content types, list definitions, list instances and seed data is fairly similar between SP2010 and SP2013 within an App.  The VS2012 tooling is good OOTB and I am using a few simple xml based tweaks to get them working as I like them.

Resolution:
Open VS2012 ensure you have the SharePoint developer addin and create the Question list as shown below.
 

Amend the list to show your fields:



Hit F5 to debug the App, edit the url to view the list you created.  My url after I edited it is shown below:
http://dev-d8f436fea036f6.apps.dev.local/KB-SPHostedApp/Lists/Question

Question list is working















Repeat the list setup process in VS for the "Comments" list.  We will start from the step where you add the related look to the Posts list.

Working Result:



Wednesday 3 November 2010

Reverse Engineer Lists, Content Types and Site Columns and retrieving the CAML

Problem: You need to create deployable lists, this should be done using a feature.  You can create a lists using the UI and then get the CAML that created the list.  The code will have some hicups but it a good place to start for building your Lists based on List definitions, content types and their corresponding site columns.

Resolution:
Get the CAML and create your feature based on the declaritive CAML
http://%7bwebapplication%7d/%7Bsite%7D/_vti_bin/owssvr.dll?Cmd=ExportList&List={ListGuid}
Thanks to Sahil Malik

Read More:
http://blah.winsmarts.com/2008-2-Dev_Tip__The_SharePoint_University_of_Reverse_Engineering.aspx
http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=24

Download: SharePoint 2010 sandbox project example that creates 2 lists with a lookup field. Updated 24/03/2011


Tuesday 12 October 2010

NullReferenceExcepetion when viewing/editing an existing list item after the list instance has been deployed

Problem: When viewing or editing and item in a list, I receive an application error (NullReferenceException).  This happens when I redeploy a list, my list is defined using site columns, content type and the list definition is based on the content type.

My ULS logs contained the following information:
Failed to cache field with id
Unable to open Lookup list 'Lists/xxxList'.[Error was 0x8007....]
System.NullReferenceException: Object reference not set to an instance of an object.   at Microsoft.SharePoint.Publishing.FieldCache.TryGetValue

Initial Hypothesis:  ULS logs show me that a lookup list is not being found.  By examining the columns on the list instance I can see they are not being created correctly.  My initial thought was my xml was wrong, once it was reviewed and I found it to be correct I realised it was a caching issue.

Resolution:  Clear the Visual Studio Cache
  1. Right click on "Project" in Solution Explorer and click "Retract";
  2. Close Visual Studio 2010; and
  3. Open the "Project" in Visual Studio 2010 and "Deploy" the solution. 

Thursday 26 August 2010

Creating lookup columns and list declaratively in SP2010

Problem: When creating lists via a feature, you may want to link SharePoint 2010 lists.
Initial Hypothesis: In MOSS to link to SharePoint 2007 lists you had to do it via the UI or via a deployable feature.  The list was created declaratively using XML (CAML).   Lastly the lookup column needed to be created using a feature receiver.  As in MOSS, in SP2010 you can create a lookup column using the UI but this is not a reusable deployment method and falls prey to errors.  SP2010 allows you to create lookup lists using declarative CAML.

Resolution: Create the lists, add site columns (fields), then add the site columns to a content type and lastly generate the list definition & list instance.  Steps are detailed below:
  • In an elements file declaratively create a lookup column that uses the specified list as shown below: 

  • Add the new lookup column to a content type:
  • Your existing/create a list definition that derives from your content type.
Note: The Lookup Site column needs to specify the list it is looking up when you declare the XML.
More Info:
Creating lists declaritively in SP2010 - Post outlines creating SharePoint lists, coupled with this post you can create lists that are related using a feature to create your lists.
Available field types

Wednesday 25 August 2010

Creating SharePoint Lists declaratively using Visual Studio 2010

Problem: Create a custom list to hold configuration values in a list.
Resolution Overview: Using VS 2010 create a feature that deploys the new list with content.
1.> Create Site Columns/fields;
2.> Create the Content Type using the Site Columns;
3.> Create the List Definition from the Content Type; and
4.> Add items to the list instance elements.xml.

Resolution Steps:

1.> Create Site Columns by adding a new "Empty Element" item in VS.
Declaratively add the site column to the elements.xml file;
Ensure your element file has been added to a feature for deployment;
Deploy the feature and ensure the Site Column has been add using the UI "Site Setting" > "Site Columns";

2.> Create the Content Type using the Site Columns
Using VS 2010 create a new Content Type;
Add caption
Using the existing Site Column create the Content Type declaratively;
Check the Content Type is create after you have deployed; 

3.> Create the List Definition from the Content Type

Follow the wizard and select the newly created Content Type "Configuration";
Check the List definition has created the elements.xml and schema.xml files;

Edit the Schema.xml File to Show the new columns defined int he content type (otherwise you will only see the "Title" column);

4.> Add items to the list instance elements.xml

Ensure the List is created



Tip: The fields/site columns & FieldRefs used in the elements files can be added thru the VS2010 tools.  VS2010 > View > Toolbar
Tip: Updated 18 Oct 2010 - CKSDev has the functionality to import Site Columns, this is useful in that you may of created the SiteColumns via the UI on a prototype site and you can not easily get the xml to create the site columns/fields declaritively.  http://blog.mastykarz.nl/cksdev-support-importing-site-columns/