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;
}