Programatically Finding Internal Names for SharePoint List Columns

Posted: November 7, 2014 in SharePoint2010, SharePoint2013

The average user usually doesn’t need to care about the ‘internal’ naming on the SharePoint lists. They just need to work. But as you start to delve into some customization approaches, trying to piece some details together behind the scenes a bit, you may need to know the internal names then.

private static string InternalColumnName(SPList oList, string NameColumn)

{

string LookupCoumn = string.Empty;

try

{

SPSecurity.RunWithElevatedPrivileges(delegate()

{

SPFieldCollection oFieldCollection = oList.Fields;

foreach (SPField oField in oFieldCollection)

{

if (oField.Type == SPFieldType.Lookup)

{

SPFieldLookup spl = (SPFieldLookup)oField;

if (spl.LookupField.Equals(ResourceNameColumn))

LookupCoumn = spl.InternalName;

if (spl.RelatedField.Equals(ResourceNameColumn))

LookupCoumn = spl.InternalName;

}

}

});

}

catch (Exception)

{ }

return LookupCoumn;

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s