SPListItem will accept the column display name OR the column internal name
-
10-12-2020 - |
Question
I am working on sharepoint server 2013. now i have the following column named "Date Reported", which have the following properties:-
- Display-Name =
Date Reported
- Internal Name =
Date_x0020_Reported
now i wrote the following code inside my console APP :-
foreach (SPListItem item in testList.Items)
{
var test1 = item["Date_x0020_Reported"];
var test2 = item["Date Reported"];
and seems both variables Test1
& Test2
got the correct date value. which means i can reference the item field value either using the field display name Or the field internal name? is this the case? and if the answer is Yes then could this cause conflicts .. let say a field internal name equal another field display name ?
Thanks
La solution
From MSDN: https://msdn.microsoft.com/library/microsoft.sharepoint.splistitem
For an indexer based on a name, Microsoft SharePoint Foundation first looks for the field by internal name and then by display name.
Conclusion:
There was no conflict, except that in the same query you're using a mixture of internal names and display names.
In general it is always advisable to use internal names.
Autres conseils
Hi Prefer using internal name while query because when change the column name to something else then the query won't work by using display name.
Try querying record by changing the column display name to something else.