«

»

mar
31

Best practice for changing the value of a column in SharePoint

In SharePoint development, it is pretty common to change the value of an element.

For instance, let’s consider the column named « Title » defined in many lists. Suppose we want to change the « Title » of an item. What’s sound straightforward is to write this

SPListItem item // get the needed item
item["Title"] = "New value";

Now to deply this solution on a French platform, and c’est le drame: Value does not fall withinh the expected range. That’s because the column is referenced here by its display name. So, for the French platform it should be

item["Titre"] = "New value";

Even worse. The display name is editable by end users (or more precisely by site administrators). Everyone get the point: this is code snippet is a worse practice.

The best practice is to use the internal name (which is « Title » for any language and will never change)

item[item.Fields.GetFieldByInternalName("Title").Id] = "New value";

And now, I can confidently say that SharePoint happy is developper unfriendly.

Note also, this sugguests another best practice: when you create a custom column: don’t use spaces in the internal name.

Lien Permanent pour cet article : http://regis.decamps.info/blog/2009/03/best-practice-for-changing-the-value-of-a-column-in-sharepoint/

  • https://www.google.com/accounts/o8/ud Régis (gmail)

    I've been incorrect with this article. it seems the short syntax uses the internal name first, and otherwise dispaly name.

    partager sur...

     

Switch to our mobile site