Tuesday, May 10, 2011

Updating values to People & Group field in Sharepoint list

string strAccountName = string.Empty;
                                for (int i = 0; i < userPicker.ResolvedEntities.Count; i++)
                                {
                                    PickerEntity objEntity = (PickerEntity)userPicker.ResolvedEntities[i];
                                    SPUserInfo objInfo = new SPUserInfo();

                                    objInfo.LoginName = objEntity.Key;
                                    strAccountName = objInfo.LoginName;
                                  
                                    if (objEntity.EntityData["SPUserID"] != null)
                                    {
                                        // to return a sharepoint people group formatted string use...
                                        strAccountName = objEntity.EntityData["SPUserID"].ToString() + ";#" + objEntity.DisplayText.ToString();
                                    }
                                    if (objEntity.EntityData["SPGroupID"] != null)
                                    {
                                        // to return a sharepoint people group formatted string use...
                                        strAccountName = objEntity.EntityData["SPGroupID"].ToString() + ";#" + objEntity.DisplayText.ToString();
                                    }
                                }


    item["ColumnName"] = strAccountName;

A sales engineer is someone who promise you a bridge, even when there's no river.