sharepoint2010的几个类型字段赋值和取值的方法

1、日期类型查询,需要转换,方法如下:
  //转换时间
   string startdate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now);
2、取用户类型的值
 public List<WorkManEntity> GetUsersFromSPFieldUser(SPListItem item,string key)
 {
     List<WorkManEntity> fUsers = new List<WorkManEntity>();
            
     SPFieldUser uField = item.Fields[key] as SPFieldUser;
     //此地方可以不判断为多选,如果单选可以除掉的
     if (uField.AllowMultipleValues)  // 允许多重选择 
     {
           SPFieldUserValueCollection userValues = item[key] as SPFieldUserValueCollection;
           foreach (SPFieldUserValue userValue in userValues)
           {
                if (null != userValue.User)
                {
                     WorkManEntity user = new WorkManEntity();
                     user.LookUpID = userValue.LookupId;
                     user.LookUpValue = userValue.LookupValue;
                     user.loginName = userValue.User.LoginName;
                     //add list
                     fUsers.Add(user);
                }
                    
           }
      }
           
      return fUsers;
 }
3、给用户类型赋值
 SPFieldUserValueCollection uvc = new SPFieldUserValueCollection();
 SPUser pu = web.EnsureUser(user.loginName);
  uvc.Add(new SPFieldUserValue(web, pu.ID, pu.Name));
 //用户类型
 newListitem[“加班成员”] = uvc;
posted @ 2013-09-10 14:21  TwinStudio  阅读(215)  评论(0编辑  收藏  举报