Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

When trying to grab a field by guid, do you need to surround the guid with {}? E.g.

field["{xxx343-xx-324-xxx}"]

or

field["xxx343-xx-324-xxx"]

share|improve this question
    
Which SharePoint API you are referring to? –  Ashish Patel Feb 28 '12 at 23:57
    
I am using SharePoint 2010 –  Meyer Denney Feb 29 '12 at 0:02
add comment

1 Answer 1

up vote 2 down vote accepted

SPListItem has 3 "Item" methods defined that take an identifier between brackets:

  • item[string fieldName]
  • item[int index]
  • item[Guid fieldId]

You seem to be trying to use item[Guid fieldId], but you are providing a string, not a Guid structure, so in effect you are calling item[string fieldName] and thus SharePoint expects a field name, not a field id.

You should be calling your method like so:

item[new Guid("{936DA01F-9ABD-4d9d-80C7-02AF85C822A8}"]

to properly form a Guid structure. With or without curly braces { } or parenthesis ( ), as the Guid constructor accepts both. Do NOT use square brackets [ ].

share|improve this answer
    
Thats what I was lookking for, but do I need to use item[new Guid("{xxx343-xx-324-xxx}"]? –  Meyer Denney Feb 29 '12 at 0:34
    
Yes, with the new sorry. Edited my post. You can include curly braces or not, both will work. –  Louis Feb 29 '12 at 2:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.