kamagra how much to take

Returning GUID’s For Internal SharePoint Fields

So, a friend today asked me a pretty straightforward question.

What is the easiest way that one can grab the GUID of the internal fields that SharePoint provides? What is the most efficient, clear, and maintainable way across environments to consistently provide a reference to built-in fields such as:

FullName
Picture
Survey Title
etc.
The best way to do this is to use the SPBuiltInFieldId class. This is because it natively provides an identifiable way to access to all the internal fields that you would normally use, ensuring consistency and readability of your code.

For example, one could use it in combination with SPListItems when creating custom interfaces to standard SharePoint lists. You could even use this to create a metadata Hashtable, which is useful in its own right.

Normally, the way that several pieces of documentation will advise you to go about such a task is to pass in the field name that you want to insert something into by specifying a string literal coordinating to the field name, somewhat messy IMHO.

This would take on the form of:

  1. SPListItemCollection listItems = SPWeb.Lists["My List"].Items;
  2.  
  3. SPListItem item = listItems.Add();
  4.  
  5. item["My Field"] = "string for insertion";

This isn’t very good for several reasons, mostly because the field name is prone to typographic problems.

Now, let’s do the same thing, however using the SPBuiltInFieldId class.

  1. SPListItemCollection listItems = SPWeb.Lists["My List"].Items;
  2.  
  3. SPListItem item = listItems.Add();
  4.  
  5. item[SPBuiltInFieldId.{Type}] = "string for insertion";

That type could take on many formats, depending on the exact field you are wanting to insert the values into. Instead of taking a string literal to insert the field, integrity is elevated since we are instead passing in the GUID as provided by the SharePoint OM.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>