SaguiItay

My blog has moved!

You should be automatically redirected in 4 seconds. If not, visit:
http://itaysagui.wordpress.com
and update your bookmarks.

Wednesday, September 14, 2011

SharePoint Client Object Model: Verifying if a Field is part of a Content Type

Before adding a field to a ContentType, it is important to check that the field is not already part of the Content Type. Here's an extension method to ClientContext that does just that:

public static bool ExistInContentType( this ClientContext clientContext, ContentType contentType, Field field)
{
	var fieldLinks = contentType.FieldLinks;
	var existingFields = clientContext.LoadQuery(fieldLinks.Where(fl => fl.Id == field.Id));
	clientContext.ExecuteQuery();
	var existingField = existingFields.FirstOrDefault();
	if (existingField != null)
		return true;
	return false;
}

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home