Tuesday, April 5, 2011

Unique Columns

You can create unique column (meaning the column will hold the unique data) inside a list in SharePoint 2010. The unique column MUST be indexed. So while creating the unique column, SharePoint 2010 will ask you to index the Unique Column. E.g. Student “Registration No” can be a unique column in the “Student” list. You can also make any existing column as unique column provided it has unique data for all the list items.
JOIN and Querying Data from Two Lists:-
Developers can query the SharePoint 2010 List using CAML and LINQ to SharePoint and select fields from two different lists as shown in the code below. Here in the below code ( LINQ To SharePoint), I have retrieved all the “Students” for the Department “Computer Science”.
Note: - In order to use LINQ to SharePoint you have to generate the “SharePoint Context” from the SPMetal tool (now comes as a part of SharePoint 2010), which is located at the following directory. (“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN”). Here is syntax to generate your Context.cs file.
SPMetal /web:http://mossserver:8000 /namespace:SPTeamSite /code:SPTeamSite.cs
After this create a new project in VS2010, add the reference to Microsoft.SharePoint.Linq.dll & Microsoft.SharePoint.dll located at the following directory. (“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI”). Also add the SPTeamSite.cs file generated from the SPMetal tool. See the diagram below.
Now here is the code to retrieve all the “Students” of a particular “Department”.

Note: We can set unique constraints to the list or lirary programtically. For this, plse refer the below url:
Setting Unique Constraints Programmatically:

No comments:

Post a Comment