Co-authoring in Office Word 2010

So, you have heard of this wonderful thing called co-authoring in Word/PowerPoint/Excel 2010 and very eager to try it out?

 

If you have SharePoint 2010 + Office 2010 installed, then you are all setup to try out co-authoring right away! Yes, no extra setup needed! It should also work with SharePoint Foundation 2010.

 

Before going forward, let me remind you that co-authoring in Word and PowerPoint is only supported in the rich clients which means that it is not supported in the web applications. I haven’t worked with Excel, so not sure what is the story with Excel 2010.

 

There is only one requirement needed: You need to disable check-out for the document library. This is because, if you enable check-out, then the document gets locked by the user and hence you wont be able to co-author:

 

image

 

Co-authoring Demo

So, here is my first user Dan opening a document from the SharePoint 2010 document library. Another user Kim also opens the same document from the document library. Now, after 30 seconds (that seems to be the refresh time for each change), you should be able to see the user icon appear at the bottom bar of the Word 2010:

 

image

 

image

 

Presence/OCS integration is right out of the box!

 

So, if Kim adds/changes the document, Dan is going to those changes through. You should see something like this:

 

image

 

Once updated, it will show the updated content

 

image

 

If the other user is editing the existing content, you will get notified too:

 

image

 

If users want to chat, they can do so instantly!

 

image

 

Backstage also shows the currently editing people:

 

image

 

When all the editing is done, you can save the document back to the SharePoint document library.

SharePoint 2010 List Validation Formulas

SP2010 Validation Formulas

Earlier, I wrote a post on Column Validation and List Validation settings in SharePoint 2010. If you are wondering where to get help for the currently supported formulas for SharePoint 2010 beta 2, then here is the ‘precious’ link for you - http://bit.ly/sp2010-formulas

 

If you are still stuck with any of the formulas, feel free to discuss it at the SharePoint 2010 MSDN Forums

Download SharePoint 2010 VHD

Update: SharePoint 2010 VHD is available now for all to download. Download here - http://bit.ly/bUILD0

 

image

If you (or your company) is Microsoft SharePoint Deployment Planning Services (SDPS) partner, then the SharePoint 2010 Beta 2 virtual machine is finally available for you to download and start using.

Sign in to your SDPS partner portal for more details! :)

Building and Deploying BDC Models in SharePoint Foundation 2010

** Note: The problem and solution discussed below applies for SharePoint 2010 public beta. Future versions may avoid the need to copy this DLL from SharePoint Server. **

 

One of the cool things about SharePoint Foundation 2010 (the ‘free’ version) is that it supports Business Connectivity Services – which means you can build Business Data Connectivity(BDC) models and deploy to your site.

 

The Problem

 

If you have already tried building one (custom .net assembly), you will encounter the following error:

 

Failed to load receiver assembly "Microsoft.Office.SharePoint.ClientExtensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"


clip_image002

 

The Solution

 

The solution is very simple – If you have SharePoint Server 2010 beta installed, copy the Microsoft.Office.SharePoint.ClientExtensions.dll from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI to the following locations where SharePoint Foundation 2010 is installed:

 

1) GAC

2) C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI

 

Now,  deploying your BDC model (custom .net assembly) from visual studio should work :)

 

SharePoint 2010 and Forms Based Authentication

If you are planning to use Forms Based Authentication(FBA) for your SharePoint 2010 site, here is an excellent step-by-step procedure to configure so:

 

Update: For SharePoint 2010 RTM, follow this blog post: http://bit.ly/a5WhlE


HOW TO:Forms Based Authentication (FBA) on SharePoint 2010


The above link covers setting up FBA using Classic Mode Authentication. If you are looking to configure using Claims Based Authentication, you can refer the following blog post:


Configuring FBA in SharePoint Server 2010

SPTechCon – The SharePoint Technology Conference

SPTechCon_1

Coming February 2010, there is another SharePoint Conference – SPTechCon in San Francisco February 10-12, 2010. Whether you are a SharePoint user/developer/IT pro, this conference covers everyone and has a total of 101 sessions and workshops for your needs!

I will be presenting the following workshop and session at the conference and will be looking forward to meet you all!

Topic: SharePoint 2010: Developing With Data Technologies

Audience: Developers

Technical Level: Intermediate

When: Wednesday, February 10, 1:30 - 5:00pm

SharePoint provides a wealth of features and services which allow developers to quickly develop solutions to organizational problems. Developers can quickly create solutions with relate data, connect to other systems, manage a process flow, and can be deployed anywhere. SharePoint 2010 opens up a wide range of options, namely:

1. SharePoint List Lookups and Relationships

2. LINQ to SharePoint

3. Client Object Model

4. REST/ADO.NET Services

This three hour deep dive workshop will take you through the various steps of building SharePoint applications using the new Data Technologies.

Visual Studio 2010 Tools for SharePoint

Audience: Developers

Technical Level: Intermediate

When: Friday, February 12, 11:30am - 12:45pm

For SharePoint developers, Visual Studio 2010 not only provides a provides the development environment and native tools, but also the opportunity to engage in SharePoint development. Visual Studio 2010 Tools for SharePoint (VSTS) provides a rich developer experience for building SharePoint 2010 applications. Whether you are looking to build a simple web part or advanced SharePoint development, VSTS helps developers to get started right away on solution development. The most interesting part is the ability to extend this framework. This session will take you through the various features of VSTS, building complex and simple SharePoint applications using VSTS and also extending the framework.

Troubleshooting your SharePoint 2010 Errors

So, you are running SharePoint 2010 Beta2, you have built sites, done some custom development and also deployment and then suddenly one fine day you get an error like this:

image

I can hear you shouting how the hell this error message is useful for me!

Well, there is nothing to panic here as SharePoint logs every error message. All you need is the ULS Viewer from MSDN Code Gallery. This is great tool which allows you to browse through the SharePoint logs and works great with SharePoint 2010. If you are getting an error, something like in the above screenshot, SharePoint would have logged it back in its log file with more technical information. It is just not visible to the end user.

So, go ahead, download the ULS Viewer and open it.

Open the ULS log from File | Open From | ULS or you can press Ctrl + U

image

Wait for few seconds (to a minute) for the ULS Viewer to load the logs.

This will open the real time log. Remember, you can also open a log file than the real time ULS log which would be the latest log file. The log files are located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS – So, make sure you open the right log file, else you wont be able to filter the results as described below.

From the error message, grab the Correlation ID, in our case it is c7832894-4b2d-4bc3-9517-430501c581ec

In the ULS viewer, click the Filter icon (image )

Select Correlation from Field – Select Equals from Operation – Enter the Correlation ID in the Value

image

Click OK button and you should see the filtered results

image

Now the results are way much better and very precise (some of my error messages below):

Name=Request (GET:http://demo2010a:80/Lists/CreateBlogSiteWorkflow-ListInstance1/AllItems.aspx)

Failed to determine the setup path of the list schema for feature {C28066FF-F2C4-4D05-B63C-39CC1E0349EA}, list template 107.

So, make sure you get hold of the Correlation ID and the time of the error to open the proper log file when such errors occur. This would be very helpful when you are reporting bugs or asking help at the MSDN SharePoint 2010 forums.

Deactivate Features Deployment Step for SharePoint 2010

If you are developing SharePoint 2010 applications in Visual Studio 2010, you would wonder why there is no Deactivate Features deployment step available but only Activate Features deployment step.

image

This becomes a problem when you retract your solution as the features do not get deactivate from the site.

Let me introduce to my first Visual Studio 2010 Tools for SharePoint 2010 extension – Deactivate Features Deployment Step 

Deactivate Features Deployment Step is an extension for Visual Studio 2010 tools for SharePoint 2010. Use this deployment step to deactivate features in a local SharePoint site.

deactivate_features_step

It is available for download at the Visual Studio Gallery or from your Visual Studio 2010 Extensions Manager

image

BDC .NET Assembly Connector: Tame SharePoint Search to search your .NET BDC Entity

So, now you have built your BDC .NET Assembly Connector and even added write operations to it. The next big thing you would think is – Can I tell SharePoint to search this BDC model?

Of course, you can! But there are few things you need to do in your BDC model in order for SharePoint to crawl your BDC model.

The BDC model exposes operations or methods through which SharePoint is going to interact with the external data sources. In our previous example, we had 3 operations:

  1. ReadItem – Read Operation returning a single entity
  2. ReadList – Read operation returning a collection of entities
  3. Update – Write operation updating a single entity

So, when you want SharePoint to crawl the BDC model, we need to tell SharePoint which operation to use in order to gather the data.

The RootFinder Method

With the BDC models, we can set properties on operations, entities, LOB instances etc., that let SharePoint identify certain extra capabilities. If a finder method has its RootFinder property set, then SharePoint will know that it has to enumerate the entities to crawl.

In our sample, the ReadList method is going to return all the entities and thus we can set the RootFinder property on this method.

Switch to your BDC Explorer, and click on ReadList. In the properties, click on Custom Properties button and add the RootFinder property as in the screenshot below:

NameRootFinder

Type – Select System.String from the dropdown

Valuex

RootFinder

Switch to the designer pane and click on the ReadList method:

BookEntity

In the BDC Method Details pane below, click on ReadList instance under Instances under ReadList method:

ReadList Instance

In the properties, click on Custom Properties button and add the RootFinder property as in the screenshot below:

NameRootFinder

Type – Select System.String from the dropdown

Valuex

RootFinder

Remember, since we want the ReadList method to be the RootFinder, we are doing this. If you have any other method, you can set this property for that method instead of the ReadList method.

Setting the ShowInSearchUI Property for the Lob System Instance

Not only we need to set the RootFinder property for the specific finder method, we also need to set the ShowInSearchUI property on the LobSystemInstance to true. This will tell SharePoint that this particular LobSystemInstance should be used in Search UI. Unfortunately, currently this can only be done via code. Below is the code to set this property on the BooksListBdcModelInstance. Just create a simple console application and execute the following code. You need to add the BDC Admin Object Model references which are as follows:

NOTE: The following is only applicable for the current Beta 2 release which is publically available. Things might change in the later builds.

  1. Microsoft.BusinessData from C:\Windows\assembly\GAC_MSIL\Microsoft.BusinessData\14.0.0.0__71e9bce111e9429c\
  2. Microsoft.SharePoint.BusinessData.Administration.Client from C:\Windows\assembly\GAC_64\Microsoft.SharePoint.BusinessData.Administration.Client\14.0.0.0__71e9bce111e9429c\
  3. microsoft.office.sharepoint.clientextensions.intl from C:\Windows\assembly\GAC_MSIL\microsoft.office.sharepoint.clientextensions.intl\14.0.0.0__71e9bce111e9429c\
static void Main(string[] args)
{
AdministrationMetadataCatalog catalog =
AdministrationMetadataCatalog.GetCatalog("http://demo2010a");
Model bdcModel=catalog.GetModel("BooksListBdcModel");
LobSystemCollection lobs = bdcModel.AllReferencedLobSystems;

LobSystem flatFileBDCModel = (from l in lobs
where l.Name == "BooksListBdcModel"
select l).FirstOrDefault();
if (flatFileBDCModel != null)
{
LobSystemInstance flatFileBDCModelInstance
= (from ls in flatFileBDCModel.LobSystemInstances
where ls.Name == "BooksListBdcModelInstance"
select ls).FirstOrDefault();

if (flatFileBDCModelInstance != null)
{
Console.WriteLine("Updating ShowInSearchUI property for " + flatFileBDCModelInstance.Name);
flatFileBDCModelInstance.Properties.Add("ShowInSearchUI", "true");
//flatFileBDCModelInstance.Properties.Remove("ShowInSearchUI");
flatFileBDCModelInstance.Update();

flatFileBDCModel.Update();
}
}

bdcModel.Update();

Console.ReadKey();
}

We are using the BDC Admin Object Model and:

  1. Connect to the SharePoint Site – change the site from http://demo2010a to your SharePoint site
  2. Get the Catalog – which is BooksListBdcModel
  3. Get the Lob System – which is again BooksListBdcModel
  4. Get the Lob System Instance – which is BooksListBdcModelnstance
  5. Set the property to true

BDCModel

Configure SharePoint Search

Creating the BDC Content Source

Go to the Search Administration in Central Admin – Central Administration | Application Management | Manage service applications | Search Service Application and create a new Content Source

Select the Content Source Type as Line of Business Data

Content Source Type Options

Select to crawl selected external data sources and select BooksListBdcModelInstance

External Data Source Options

Select to start a full crawl and click OK. This will start a full crawl of the content source.

Wait till the full crawl is over.

Updating the Scopes

Now go to your scope where you want to include this content source and create a new rule to include this content source:

Scopes

Click OK.

Wait for the scope to be updated. This might from few seconds to few minutes depending on the content (It took 18 minutes for me!) or You could start the update manually from the Search Administration page. Look for Scopes updates status in the System Status.

Perform Search

Once the content source is crawled and scopes updates, perform the search from the site. For our books entity, enter any ISBN number, say for example 0470099410 in the search text box and hit the search button.

You should see the search results showing up!

BDC Search Results

(Clicking on it will not take you to the list item though)

BDC .NET Assembly Connector: Updating a BCS Entity

In my previous post, I showed you how to build a simple BDC model using the .NET Assembly Connector. SharePoint 2010 not only allows to perform read operations from external data sources, but also supports write operations to external data sources. This allows us to update or delete an entity (based on the Identifier). In this post, we will extend our previous BooksList BDC Model to include write operations.

To make the update process simpler, I have slightly modified the previous code. I have now introduced a static List that holds the list of all books and build the entity in ReadList and ReadItem methods from the static List.

The Changes

The new books list:

static List<string> books = new List<string>
{
    "0470099410,Book1,Author1,$25.50,Publisher1",
    "0470099411,Book2,Author2,$35.50,Publisher2",
    "0470099412,Book3,Author3,$45.50,Publisher3",
    "0470099413,Book4,Author4,$55.50,Publisher4",
    "0470099414,Book5,Author5,$65.50,Publisher5"
};       

The updated ReadItem method:

public static BookEntity ReadItem(string id)
{
    string book = books.FirstOrDefault(s => s.Contains(id));
 
    if (book != null)
    {
        string[] b = book.Split(',');
 
        return new BookEntity
        {
            ISBN = b[0],
            Name = b[1],
            Author = b[2],
            Price = b[3],
            Publisher = b[4]
        };
    }
 
    return null;
}

The updated ReadList method:

public static IEnumerable<BookEntity> ReadList()
{
    //TODO: This is just a sample. Replace this simple sample with valid code.
    List<BookEntity> booksList = new List<BookEntity>();
    BookEntity bookEntity;
 
    foreach (string book in books)
    {
        string[] b = book.Split(',');
 
        bookEntity = new BookEntity()
        {
            ISBN=b[0],
            Name=b[1],
            Author=b[2],
            Price=b[3],
            Publisher=b[4]
        };
 
        booksList.Add(bookEntity);
    }
 
    return booksList;
}       

Current Operations in the external list

If you browse to your list and open the ECB menu, you can see there is only View option available:

View Operation

Adding the Update Method

In your BDC diagram pane, click on the entity to reveal the BDC Method Details pane.

BDC Method Details

At the bottom you can see the option to Add a Method. Click on that to reveal the available options:

Methods Available

Click on Create Updater Method. This will add the Update operation to the BDC model.

Update Method

And the diagram pane is also updated to hold the new Update method:

BookEntity

Update Operation Parameters

By default, the update method adds the entity as the only parameter of type In which means that this will be coming into the .NET Assembly Connector from SharePoint list. But for our demo, we have set the ISBN property as the Identifier and this is going to be the key field in terms of finding the required book. So, we should have another parameter of type In which is of type String and will be the ISBN property.

Click on Add a Parameter and select Create Parameter in the Update method in the BDC Method Details pane. This will create a new parameter.

Update Method

Switch to BDC Explorer and you can see the new parameter added:

BDC Model

Click on the new parameterTypeDescriptor. In the Properties pane, change:

  1. Name to ISBN 
  2. Set the Pre-Updater Field to True
  3. Select the Identifier as ISBN

Parameter Properties

We have now set that this parameter of name ISBN is the Identifier and a pre-updater field which essentially tells BDC to preserve the field’s previous value when the entity is being updated.

In the diagram pane, double click on Update method to open the code behind

Adding Update Code

Below is my update code:

public static void Update(BookEntity bookEntity, string parameter)
{
    string book = books.FirstOrDefault(s => s.Contains(parameter));
 
    if (book != null)
    {
        int index = books.IndexOf(book);
 
        books.RemoveAt(index);
 
        books.Insert(index,
                     String.Format("{0},{1},{2},{3},{4}",
                                    bookEntity.ISBN,
                                    bookEntity.Name,
                                    bookEntity.Author,
                                    bookEntity.Price,
                                    bookEntity.Publisher));
    }
} 

We are only updating the List and when BDC calls ReadList operation for refreshing, it will pick up the updated books List, iterate and build the entity.

Build and deploy your solution.

Edit Item

Now you can see that you have the option of Edit Item

Entity

Click on Edit Item and you will be presented with the dialog window to edit the current item :)

Edit Entity

Change the Author from Author1 to New Author and click Save

You should see the updated value for that entity!

Updated Entity

P.S: If you encounter any errors clicking Edit Item, please re-create the External List. I am not sure the cause of the problem, but will investigate and update on this issue in this post as soon as I find the cause.

You can download the source code here

Building a BDC Model using the .NET Assembly Connector

My previous post on BCS Walkthrough showed how to make use of the SQL Server Connector, connect to a database,and bring the data back to SharePoint 2010. This used the SQL Server as its data source. If you want to bring the data back from a WCF service, there is the out of the box WCF Service Connector.

What if your external data source is not SQL Server or a web service, and is some custom .NET assembly or a flat file? This is where the .NET Assembly Connectors come into picture. Developers can build & design their custom model & entities using Visual Studio 2010, thereby help the BCS to interact with the custom data sources. The .NET Assembly Connector is nothing but a .NET assembly that acts as a proxy to interact with the external data source.

Lets explore this .NET Assembly Connector with a simple example.

I would also recommend you to watch the BCS Overview Demo videos if you are not familiar with BCS.

External Books List

So, I have this external books list that I want to bring into my SharePoint 2010 site. The list has the following properties associated with it:

  1. ISBN
  2. Name
  3. Author
  4. Price
  5. Publisher

BDC Model Project

Open VS2010 and select the Business Data Connectivity Model project template

BDC Project Template

Once the project is created, you will be presented with the simple entity called Entity1with two read operations:

  1. ReadList
  2. ReadItem

Entity1

The names suggest what they do. ReadList operation is going to return you the full list (list of Entity1) and the ReadItem is going to read a single item (Entity1). You can see the same in the BDC Model Designer:

BDC Explorer

If you explore the Solution Explorer, you will see the class files and the feature associated with this BDC project

BDC Explorer

The Entity1 class corresponds to the Entity1 entity and has its properties defined. The Entity1Service class implements the operations, that is ReadList and ReadItem.

Entity Classes

Modifying the Entity1 Class

We can now modify the Entity1 class to BookEntity and declare the properties. Rename the Entity1.cs to BookEntity.cs

The ISBN will be our Identifier or the primary key with which a book is identified.

BookEntity

Modifying the Entity1Service Class

Rename the Entity1Service.cs to BookEntityService.cs.

Create a simple books array. For the simplicity of this post we are using Objects. This data can also come from a flat file.

booksList

Modify the ReadItem to return the book matching the id, which is the ISBN property:

ReadItem

Modify the ReadList to return the list of all books:

ReadList

Update the BDC Model Designer

Now that we have modified the code to do what we want, it is time to modify the BDC Designer model. Double click on BdcModel1.bdcm in the Solution Explorer to open the designer. Switch to BDC Explorer.

Go ahead and rename the BdcModel1 to BooksListBdcModel and the BdcModel1 in the LobSystemInstances to BooksListBdcModelInstance

BooksListBdcModel

Rename the Entity1 to BookEntity matching our entity name.

In the BDC Model, rename Identifier1 to ISBN

BookEntity

Switch to BDC Explorer and expand ReadItem operation and change the Identifier1 to ISBN under @id

BDC Explorer

Rename the Entity1 in the @returnParameter to BookEntity and delete the Message type descriptor node. Then rename the Identifier1 to ISBN

BookEntity

Right click on BookEntity node and select Add Type Descriptor. It will add a new type descriptor node:

BookEntity

Rename it to Name.

Do the same and add Author, Price and Publisher. Below is how it will look after adding these properties. Make sure you explore the Properties window and check the type name to be System.String

BookEntity

Expand ReadList operation.You can see that the Entity1 is listed again as the return parameter.

BookEntity Operations

You don’t have to create them again, instead we can copy from the ReadItem operation and paste the BookEntity here. In the ReadItem, right click on BookEntity and select to Copy

Copy BookEntity

Right click on Entity1List and select Paste

ReadList Return Parameter

You can now safely delete the Entity1 node. Rename the Entity1List to BookEntityList

Below is our modified BDC Model

BDC Model

For more details on these functions, switch to the diagram pane and click on the BookEntity and this should reveal the Method Details Window:

BDC Method Details

You can see that @id parameter is a parameter that is going to come into the .NET assembly (which is the proxy and is BookEntityService class) and @returnParameter is of return type that this .NET assembly operation is going to return. So now it makes clear that ReadItem is accepting @id parameter which corresponds to the ISBN property (type descriptor) and returns a @returnParameter which is of type BookEntity. The ReadList returns @returnParameter which is of type BookEntityList which is a collection of type BookEntity.

Based on your needs, you can add new methods, define parameters and implement them.

Build and deploy your solution.

Verifying the BDC Model

Browse to your Central Admin and open Application Management | Manage service applications | Business Data Connectivity

You should see the BDC model we just built and deployed

BookEntity Content Type

Click on BookEntity to explore the fields and various other properties

BookEntity External Content Type Information

Create the External List

Browse to your Site. Click on Site Actions | View All Site Content and then Create

Choose External List from the Content and Data category and click Create

Create Options

Give a name to your list and choose the BooksListBdcModelInstance as your external content type. You can use the picker to pick

BDC Picker

Create External List

Click Create to create the list.

And here is our list pulling external data from our .NET assembly!

External List

You can download the sample here.

MSDN and TechNet Subscribers: Download SharePoint Server 2010 Beta2 and Office 2010 Beta2

So, Microsoft has just released a wave of (beta) products to download for MSDN and TechNet subscribers.

image

If you are looking to get your hands dirty on the latest and greatest SharePoint 2010, then this is the perfect time.

SharePoint 2010: Building a SharePoint Console Application

If you are using SharePoint Server 2007 to build a console application, you would do something like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
 
namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite spSite = new SPSite("http://demo2010a"))
            {
                using (SPWeb spWeb = spSite.RootWeb)
                {
                    Console.WriteLine(spWeb.Title);
                }
            }
 
            Console.WriteLine("Done!");
        }
    }
}

If you take the same code, execute it against SharePoint 2010, you will be surprised (at least for the first time) to see VS2010 throw an error!

Console Application Error

There is nothing wrong with your code, except that now SharePoint 2010 is 64bit!

You got it right, your SharePoint Server 2007 console application’s target platform would have been x86(32 bit) and you need to change that to x64(64 bit) in the Build configuration of your project.

x64 Platform Target

The other thing to make sure is that the target framework is .NET 3.5.

SharePoint 2010 List Improvements – Column Validation and List Validation Settings

Another great improvement in SharePoint 2010 is that now you can specify formulas that validate the columns based on other columns!

Let me take you through an example.

Here is a simple list called Scores

Scores List

It stores the student scores for Paper 1 – Paper 5 , total score and the result. The scores are values between 1 to 100.

[ This is still doable without any formulas by setting the maximum and minimum values for the Number column. But I am using this example to illustrate the Column Validation. But there is still one advantage of using validation than using the maximum and minimum setting :) ]

Let us add a new item:

Ad dnew Score item

Looking at it, it is obvious that Paper 2 has a score of 150 and is invalid. So, we should be showing some error messages so that users get notified that the information entered is invalid.

Column Validation

In SharePoint, now columns have a new section called Column Validation where you can enter formulas (similar to Excel formulas) to pass validation.

Column Validation

You can enter the formula and the corresponding message that you want to display to the users if the validation fails. [You can customize the error message the way you want if you this validation than using the maximum and minimum settings :) ]

The formula is pretty similar to Excel. I also remember seeing some SharePoint functions (in the early builds), but the help is currently unavailable so we have to wait till the public beta is released.

Remember, this is a column validation and not list validation, so if its created at the site level, it will apply everywhere.

List Validation

You can do the same thing at the list level. You can access this in the List settings page:

List Validation Settings

List Validation

The only difference is now you know what are the columns you would be validating against.

Validation in action

Here is validation in action:

Validation in action

Notice how it changes the focus and also displays the error message below that particular column.

Validation via code

For the developers out there, here is how you can set the validation formula and message via object model:

using (SPSite spSite = new SPSite("http://site"))
{
using (SPWeb spWeb = spSite.RootWeb)
{
SPList lstScores = spWeb.Lists.TryGetList("Scores");

if (lstScores != null)
{
SPFieldNumber fldPaper1 =
lstScores.Fields.GetField("Paper 1") as SPFieldNumber;
fldPaper1.ValidationFormula =
"=AND([Paper 1]<=100,[Paper 1]>0)";
fldPaper1.ValidationMessage =
"Invalid score entered. Please enter a value between 1-100.";
fldPaper1.Update();
}
}
}
 
Note: Lists.TryGetList is a new method which you can safely use to get a SPList object. If the list doesn’t exists, it returns null.

SharePoint 2010 Lists Improvements – List Lookups and Relationships

SharePoint 2010 brings in quite a few changes to Lists in SharePoint, especially in the lookup columns and enforcing relationships.

When you create a Lookup Column in SharePoint 2010 which fetches data from another List’s field, you can now add additional lookup fields and not just the identifier field!

image 

Along with adding additional lookup fields, you can also enforce relationships so that it allows a cascade delete or restricts delete if a relationship still exists:

image

So, if there is a relationship associated, then you get this lovely error message when you try to delete an item (relationship behaviour configured to Restrict delete):

image

A Powerful Example to showcase List Relationships

Well, there isn’t much if I just show you the new options in lookup fields and relationships. Here is an example to show how powerful the relationships are in SharePoint 2010!

Projects and Employees List

So, I have two lists Projects and Employees list:

image

image

As you can see the Projects list has a lookup field Primary Contact which links to the Employees Fullname field. And the Employees list has a lookup field Project referring to the Project Title field.

If you click on a Project item, you get to see the project details, which is obvious:

image

Now, I would also like to see all the employees associated with this project. Given that we already have linked Projects and Employees list, this is certainly doable. You would go about asking any of your developers to build a web part that would do this job. With SharePoint 2010, its just plain simple with few steps :)

All we need to do is edit the default display form and add the Employees list!

In the SharePoint Ribbon (when you are on the List page, click on List in the Ribbon), select to edit the default display form:

image

This is the form that displays when you view an item.

This will open the default display form page in edit mode. Notice that the Ribbon now has Insert tab. Click on Insert and you will find the Related List button!

image

You can see the Employees list listed there! As it says, inserting this related lists web part will display related Employees items based on the Project lookup column! Go ahead and insert the list:

Below is the display form page with the related list web part added:

image

Save the page, and now, clicking on a Project item, you can see all the Employees associated with that particular project!

image

That wasn’t hard! Now, this is what I call a ‘killer-feature!’ :)


Creative Commons License
Chaks' Corner Blog by Chakkaradeep Chandran is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Based on a work at www.chakkaradeep.com.
Permissions beyond the scope of this license may be available at http://www.chakkaradeep.com.