Pages

Wednesday, September 15, 2010

Error when trying to update person or group type field type insharepoint List

Hello Friends

 I found one error when I was trying to assign value to List Column which has field type as “Person/Group”. I have one list name as Project and in that list I have column name as “ProjectManager” which has type “Person or group” when I am trying to assign values by programmatically Like below line. listItem["projectmanager"] = "Domain Name\\User Name";

It gives error: Invalid data has been used to update the list item. The field you are trying to update may be read only.

How can we edit or assign value to “Person or group”. I searched and researched and I found solution how can we assign or edit the item which has “Person or group” field type. For that we have to keep in mind some of matters. We can do that thing by:

Spweb Web = Spcontext.Current.Web;

……………………………………………………….

………………………………………………..

Contains code for list declaration and item newly created declaration.

 listItem["projectmanager"] = Web.AllUsers["DomainName\\UserName"].ID;

The thing we have to keep in mind is we have to specify user name not only name of user but with Domain Name.We have to give that person's ID to person/Group Field Type

Disha Shah

No comments:

Post a Comment