views:

73

answers:

1

Let's say I have a string array of field internal names. How do I get their display names?

I've been searching for an answer and found that there is a SPFieldCollection(SPWeb web, string strXml) constructor. My first thought - yeehaw, i can pass a CAMLquery and get SPFieldCollection objects to work with.

However for strXml I've tried passing following CAML query:

  • <FieldRef's> (<FieldRef Name='Abc'><FieldRef....)

  • <ViewFields><FieldRef's></ViewFields>

  • <Fields><FieldRef's></Fields>

but unlucky. No results.

Any ideas on how to do this?

+1  A: 

Is there any reason in parcitular you don't want to loop through the names and call

web.Fields.GetField( internalName )

for each name?

One drawback from this approach is that GetField will fallback onto display name matching if the internal name can't be found, so if you have some funky crossovers between internal and displayname things might get a bit tricky. In that case I'd loop through the FieldCollection in stead and match the other way around, directly on InternalName.

Paul-Jan
Ohh, that probably works. Thanks.
Janis Veinbergs