In SharePoint development, when we add, delete, and modify list items, we only pay attention to common columns, such as "single line of text ", "multiple lines of text", "Choice (menu to choose from)", and so on, and these columns values are well processed.CodeIs the string, Int, datetime type, as long as the corresponding OK.
However, we may accidentally or mistakenly assign an incorrect value to a column of the type. The column type is "person or group ".
Most of the time, we can see that the value of the person or group type in the operation is displayname or loginname, And the intuitive judgment is the value of the string type. However, be careful when assigning values to columns of the "person or group" type:The data type of "person or group" is "spuser"
As follows:
In this case, assign a value to the column of the "person or group" type to the column of the stirng type. Immediately modify the code, as shown in:
Perfect, code execution passed, no problem.
Summary:
When we assign a value to a column of the "person or group" type, we must assign the "spuser" to it.Use the SharePoint built-in method to directly obtain the spuser object, AlsoYou can use the spweb. ensureuser () method to convert "domain \ Username" to a spuser object.And then assign values.