Datasheet view with Lists and content types


MOSS and Windows SharePoint Services V3. In short; the DataSheet view is not content type aware.

What does it mean?

  • Have two content types with some columns set Required = Yes

  • Assign these CT’s to a list and remove the standard one called (on English systems) “Item”

  • Add an item with the Standard View

  • Add an item with the DataSheet View

Differences?

The datasheet is not aware that columns (based on a CT) with Required = Yes must contain data.

And Why?

Compare:

Content Type is a kind of Schema definition
List is using an own Schema

That means the standard view knows how to check the CT schema to ensure that the new entry based on that schema definition.

Our DataSheet is comparable with a small application because it communicates with the SharePoint Lists WebService over the network. You can also compare the behavior if you develop an own application which communicates to SharePoint by using the Lists WebService.

The following ScreenShots I took with the SharePoint Manager we offer on Codeplex. http://www.codeplex.com/spm This tool is perfect to understand in a visual way how the Schema of a List and CT’s are working together.

image

Expand ContentTypes and you will find all linked content types you are using with the List called SPM-Test.
Check out Fields and there you will see all fields used by this List.

With SPM you can also see the differences when added a CT called MyCT with a field called AMyOwnTown (text and required) to that List. Expand the ContentTypes and Fields.

image You will find image

 

And the Schema of the Fields?
 image You will find image

 

Why I cannot rely on the Lists Webservice and the Schema of the Fields?

The content type is the “Master” and all consumers of a CT should be aware but it is still possible with the minimum of information to use only the Schema of the List-Fields. Also think about columns (fields) with the same name…

 

What to do now?

With only one CT added to a List it is easy because you are able to edit the Column AMyOwnTown.

image

 

With more than one CT?

  • By using SPM; in my test environment it worked today and I changed Required for AMyOwnTown to True.

  • Create your own small application to change the Required explicit to “your value”.

// C#
SPSite oSiteCollection = new SPSite("http://ServerName/");
SPList oList = oSiteCollection.AllWebs["/SiteDirectory/office/"].Lists["SPM-Test"];
SPFieldCollection collFields = oList.Fields;
SPField oField = collFields.GetField("AMyOwnTown");

// At the end change the required field and with UPDATE() it works....
// 08/Jun/2009

oField.Required = true;
oField.Update();

 

Additional ideas:

  • Double-Check the fields on a list with a possible used content type.

  • Create an event receiver to check used Lists and all the fields and content types.

I am talking here about the Required field because it was a support case where a customer complained the behavior of the DataSheet view. The provided DataSheet View (STSLIST.DLL) based on a control made by the Access team. With that knowledge I could assume that there is already an enhanced Sheet-View available made by one of our Vendors.

 

References:

Lists.GetListItems Method (Lists)
Returns information about items in the list based on the specified query.
Web Service: ListsWeb Reference: http://<Site>/_vti_bin/Lists.asmx

Lists.GetListContentType Method (Lists) http://msdn.microsoft.com/en-us/library/lists.lists.getlistcontenttype.aspx

Lists.GetListContentTypes Method (Lists) http://msdn.microsoft.com/en-us/library/lists.lists.getlistcontenttypes.aspx

Everything you need to know about Microsoft Office SharePoint Server (MOSS) Event Handlers.
http://blogs.msdn.com/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-you-need-to-know-about-microsoft-office-sharepoint-portal-server-moss-event-handlers.aspx

How to: Create an Event Handler Feature http://msdn.microsoft.com/en-us/library/ms453149.aspx

Building List Definitions with Event Receiver in Windows SharePoint Services 3.0 http://msdn.microsoft.com/en-us/library/bb736146.aspx

 

Suggestions?

My personal one would be to develop an event receiver to double-check new, changed and also deleted entries. Please have in your mind that there are also some other ways to add entries to that List; ie. OM, SOAP, restoring from Recycle Bin.

Questions?

Before you develop an amount of questions please check your requirements and also Test what you want to do. A developer must be able to debug own code and with other projects you also need to test your own ideas.

If you want to discuss the content of this blog post please go to one of our forums http://social.msdn.microsoft.com/Forums/en-US/category/sharepoint and refer to this blog post.

Skip to main content