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

I had expected that if TryGetFieldByStaticName succeeds and returns a value, there would be an SPField in the item that has a static name equal to what I used in the TryGet... call, but no? I.e. can someone explain why the following piece of code outputs Value: a field value bot not here it is.

// page is SPListItem from Pages list
string stName = "CustomName";
try {
  Console.WriteLine("Value: " + page.Fields.TryGetFieldByStaticName(stName));
  foreach (SPField field in page.Fields) {
    if (field.StaticName.Equals(stName)) {
      Console.WriteLine("here it is");
    }
  }
} catch (Exception ex) {
  Console.WriteLine("Not Found");
}
share|improve this question
add comment

1 Answer

Can you check if this works:

    if (field.StaticName.Equals(stName, StringComparison.OrdinalIgnoreCase))
share|improve this answer
    
Same output, unfortunately. –  claesv Oct 11 '12 at 6:46
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.