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

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

  • Monday, June 18, 2012 7:44 AM
     
     

    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

All Replies

  • Monday, June 18, 2012 8:25 AM
     
     Answered Has Code

    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 9:02 AM
     
      Has Code

    Hi Saumil,

         Its working for

    SPUser userObj = SPContext.Current.Web.CurrentUser;

    Thanks.