3

In SharePoint list I know the field display name.

Using display name I want to get Internal name of field,

string FieldName = "Test Field";
SPField field = olist.Fields.GetFieldByInternalName(fieldname);

Test Field is display name using this how can i get the internal name of field without using foreach loop.

2

You can use it as below:

string FieldName = "Test Field";

//you can pass the display name, internal name of static name in the GetField method
SPField field = olist.Fields.GetField(FieldName);

var fieldInternalName = field.InternalName;

According to this - SPFieldCollection.GetField , the GetField methods gives you the field data by passing it a string with either internal, display, or static name of the field.

Or alternatively, you can use it as below:

string FieldName = "Test Field";    

//accepts the fields display name only
SPField field = olist.Fields[FieldName];

var fieldInternalName = field.InternalName;

Reference - SPFieldCollection property to get the field data.

After that, you can use the InternalName and fetch your value.

Reference - SPField.InternalName

| improve this answer | |
  • in my case both its not working if i am using this SPField field = olist.Fields.GetField(FieldName); error - Column 'Test Field' does not exist. It may have been deleted by another user. if i am using this SPField field = olist.Fields(fieldname); //It was throwing Excpection. – Elina Aug 11 '17 at 10:46
  • thats quite strange, can you check if the spaces are correct or if the display name has some other characters ? you can go to list settings and check that – Gautam Sheth Aug 11 '17 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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