Assigning Person/Group column type value from one list to another list.


  • i am assigning value to a user column from a user column in a  list to another list using the following code

    item["Username"] = CurrentListItem["Username"].ToString();

    The code works fine when there is a value in CurrentListItem.But when there is no value in CurrentListItem it throws an null value exception.Any pointers on how to handle this will be helpful.

    Wednesday, January 01, 2014 2:20 PM


All replies

  • Can you not check if the value is null before assigning value?

        item["Username"] = CurrentListItem["Username"].ToString();


    Wednesday, January 01, 2014 2:26 PM
  • Hi Amit,

    i tried the way you told but when it comes to the condition in if loop String.IsNullOrEmpty(CurrentListItem["Username"].ToString()) itselfs it throws an error object reference not set to an instance,and it goes to catch block.


     if (!String.IsNullOrEmpty(CurrentListItem["Username"].ToString()))
                                item["Username"] = CurrentListItem["Username"].ToString();

    Thanks and regards

    Wednesday, January 01, 2014 2:50 PM
  • Then simply use this

    CurrentListItem["Username"] != null


    • Marked as answer by spdevkktt Wednesday, January 01, 2014 3:06 PM
    Wednesday, January 01, 2014 2:57 PM
  • thanks amit that worked :)
    Wednesday, January 01, 2014 3:06 PM