none
programmatically setting custom column (with datatype person/group) of a sharepoint list.

    Question

  • Hi,

       I have a custom list with one of the column as "Recruiter"(of which the datatype is person/group). I am adding list item programmatically as

    string struser = SPContext.Current.Web.CurrentUser.Name;

    item["Recruiter"]= struser ;

    item.update();

    then it thoughs the error as

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

    Please help me to resolve this if anyone knows this.

    Thanks in advance

    Monday, June 18, 2012 7:44 AM

Answers

  • Hello,

    Have you tried this?

    SPUser userObj = SPContext.Current.Web.CurrentUser;
    
    item["Recruiter"]= userObj; 
    -Saumil

    • Marked as answer by VidyaPai Monday, June 18, 2012 8:59 AM
    Monday, June 18, 2012 8:25 AM

All replies

  • Hello,

    Have you tried this?

    SPUser userObj = SPContext.Current.Web.CurrentUser;
    
    item["Recruiter"]= userObj; 
    -Saumil

    • Marked as answer by VidyaPai Monday, June 18, 2012 8:59 AM
    Monday, June 18, 2012 8:25 AM
  • Hi,

    Try this:

    string struser = SPContext.Current.Web.CurrentUser;

    item["Recruiter"]= struser ;

    item.update();

    Notice that I removed Name property from first line.

    Regards!



    José Quinto Zamora
    SharePoint and Search Specialist at SolidQ(http://www.solidq.com)
    MCITP and MCPD in SharePoint 2010
    http://blogs.solidq.com/sharepoint

    Monday, June 18, 2012 8:25 AM
  • Hi Saumil,

         Its working for

    SPUser userObj = SPContext.Current.Web.CurrentUser;

    Thanks.

    Monday, June 18, 2012 9:02 AM