sharepoint2010 当人员控件显示为中文姓名时 如何获得此人的登录名--SPFieldUserValue用法

    SPSecurity.RunWithElevatedPrivileges(delegate()        //虚拟管理员,否则其他用户访问没有权限
                   {
                       #region
                       using (SPSite site = new SPSite("http://xxxxx.com"))
                       {
                           using (SPWeb web = site.OpenWeb())
                           {
                              
                               SPList myList = web.Lists["listName"];
                               SPQuery myquery = new SPQuery();
                           
                               SPListItemCollection myItems = myList.Items;
                               //获得list 所有item
                               DataTable myItem_DT = myItems.GetDataTable();
                               myItem_DT.Columns.Add("Hierarchy", Type.GetType("System.String"));
                               myItem_DT.Columns.Add("ItemId", Type.GetType("System.Guid"));
                               //myItem_DT.Columns.Add("ReportTo", Type.GetType("System.String"));

                               labCount.Text = myItem_DT.TableName;
                               DataRow[] myItemTempRows;
                               string myItemTempUrl = "";
                               //给所有item 增加层级结构和itemGUId
                               foreach (SPListItem sItem in myItems)
                               {
                                   //i++;
                                   //获得层级结构
                                   //Console.WriteLine(sItem.Title);
                                   myItemTempRows = myItem_DT.Select("ID='" + sItem.ID.ToString() + "'");
                                   myItemTempUrl = sItem.Url.ToString();
                                   myItemTempUrl = myItemTempUrl.Substring(myItemTempUrl.IndexOf('/', 2) + 1);
                                   myItemTempUrl = myItemTempUrl.Substring(0, myItemTempUrl.LastIndexOf('/'));
                                   //TempUrl = TempUrl.Substring();
                                   myItemTempRows[0]["Hierarchy"] = myItemTempUrl;
                                   myItemTempRows[0]["ItemId"] = sItem.UniqueId;
                              
                                  
                                  SPFieldUser field = sItem.Fields["直线经理"] as SPFieldUser;
                                 
                                   if (field != null && sItem["直线经理"] != null)
                                   {
                                       string myarry = sItem["直线经理"].ToString();
                                       SPFieldUserValue GetUser = new SPFieldUserValue(web, sItem["直线经理"].ToString());
                                       string ReportTo = GetUser.User.LoginName;
                                       myItemTempRows[0]["ReportTo"] = ReportTo;
                                     
                                   }
                               }

                           }
                           
                       }
                       #endregion
                   });

你可能感兴趣的:(sharepoint2010 当人员控件显示为中文姓名时 如何获得此人的登录名--SPFieldUserValue用法)