Wednesday, August 3, 2011

Getting User Information


  #region get requestor department
                          
                            SPField pplField = oOpenItem.Fields["Requestor"]; // this is user field
                            string username = oOpenItem["Requestor"].ToString(); // get the value
                            SPFieldUser userField = (SPFieldUser)pplField;
                            SPFieldUserValue fieldValue = (SPFieldUserValue)pplField.GetFieldValue(username);

                            SPList UserInfoList = site.SiteUserInfoList;
                            SPListItem UserItem = UserInfoList.GetItemById(fieldValue.User.ID);
                            strDept = UserItem["Department"] == null ? "No Department" : UserItem["Department"].ToString();
                          

                            #endregion

SPONSORS:

No comments:

Post a Comment