SharePoint 获取Lookup 字段的值

获取某个List里的Lookup字段的值是很普遍的事,那么我们将它封装起来

获取Lookup字段值的方法:

 1         /// <summary>
 2         /// To get lookup field Id or Value
 3         /// </summary>
 4         /// <typeparam name="T"></typeparam>
 5         /// <param name="item"></param>
 6         /// <param name="fieldName"></param>
 7         /// <param name="defaultValue"></param>
 8         /// <param name="getValueType">0:return Id, 1:return Value</param>
 9         /// <returns></returns>
10         public static T GetLookupField<T>(this SPListItem item, string fieldName, int getValueType, T defaultValue)
11         {
12             fieldName = fieldName.Replace(" ", ConstVariables.blankSpicalCode);
13
14             if (item[fieldName] == null)
15             {
16                 return defaultValue;
17             }
18
19             var itemElements = Regex.Split(item[fieldName].ToString(), ";#", RegexOptions.IgnoreCase);
20
21             if (itemElements.Length >= 2)
22             {
23                 return ConvertTo<T>(itemElements[getValueType], defaultValue);
24             }
25             else
26             {
27                 return defaultValue;
28             }
29         }

调用该方法: <oldPlan是SPListItem>
1. 获取Lookup的ID:

oldPlan.GetLookupField<int>(ConstVariables.PRColumns.ColumnStatus, 0, 0);

2. 获取Lookup的Value:

oldPlan.GetLookupField<string>(ConstVariables.AllBGProfileColumns.ColumnBGName, 1, string.Empty)

时间: 2024-08-28 14:09:39

SharePoint 获取Lookup 字段的值的相关文章

SharePoint 设置Lookup 字段的值

如何设置Lookup字段的值, 首先我们同样需要了解SPFieldLookupValueCollection和SPFieldLookupValue, 这2个类的原理和之前所讲解到SPFieldUserValueCollection一样,这里就不多讲解 1 /// <summary> 2 /// Convert dropdownList value to SPFieldLookupValue 3 /// </summary> 4 /// <param name="dr

go语言 从结构体中获取某个字段的值(反射+泛型)

Go 语言提供了 user.Name 语法,来从 user 结构体中获取 Name 的值. 那么如果我们想将 Name 变成变量该如何做呢? 原型:getStructField(input interface{}, key string) (value interface{}, err error) 功能:从 input 结构体中,取出 key 字段 对应的值 代码实现: package utils import ( "errors" "fmt" "ref

Entity Framwork(EF) 7——在Controller内获取指定字段的值

一.开发背景: 在用户登录的时候,验证用户和密码是否正确.验证通过后将用户名和用户ID保存下来以便后续数据更新时使用. 二.用户验证方法: 1.创建DBContext 对象. ApplicationDbContext _context; //Controller构造函数        public FramController(ApplicationDbContext context)        {            _context = context;        } 2.查询数据

[SoapUI]怎样从应答报文中获取某个字段的值,然后用其改写某个变量

import com.eviware.soapui.support.GroovyUtils def groovyUtils = new GroovyUtils( context ) def holder = groovyUtils.getXmlHolder( "NormalUserLoginHealthTest#Response" ) def ProductID = holder.getNodeValue("//authen[1]/impsn[1]/pid[1]/text()

java对象的内存布局(二):利用sun.misc.Unsafe获取类字段的偏移地址和读取字段的值

在上一篇文章中.我们列出了计算java对象大小的几个结论以及jol工具的使用,jol工具的源代码有兴趣的能够去看下.如今我们利用JDK中的sun.misc.Unsafe来计算下字段的偏移地址,一则验证下之前文章中的结论,再则跟jol输出结果对照下.怎样获取sun.misc.Unsafe对象.能够參考这篇文章. public class VO { public int a = 0; public long b = 0; public static String c= "123"; pub

利用sun.misc.Unsafe获取类字段的偏移地址和读取字段的值

我们列出了计算java对象大小的几个结论以及jol工具的使用,jol工具的源码有兴趣的可以去看下.现在我们利用JDK中的sun.misc.Unsafe来计算下字段的偏移地址,一则验证下之前文章中的结论,再则跟jol输出结果对比下.如何获取sun.misc.Unsafe对象,可以参考这篇文章. [java] view plain copy public class VO { public int a = 0; public long b = 0; public static String c= "

CRM 客户端程序开发:获取表单界面上各种字段的值及其他属性

我们写程序常用的就是获取字段的值,对于不同的字段类型,通过getValue() 获取到的值如下,这个表摘自SDK中的 Xrm.Page.data.entity attribute (client-side reference) 章节. Attribute Type Return Type boolean Boolean datetime Date To get the string version of a date using the Microsoft Dynamics CRM user's

sharepoint查阅项(lookup)字段级联的实现(By InfoPath)

InforPath实现的好处是不需要写代码,缺点是发布后表单样式会发生变化.下面开始介绍InfoPath实现方法: 一.首先需要准备3个表,表1为设备类型表,存放设备类型信息: 表1 表2为设备表,存放设备信息,其中设备类型字段为lookup类型,指向的是表1中的标题字段: 表3为设备申请表,存放申请信息,设备类型和设备名均为lookup类型,分别指向表1的标题和表2的标题字段. 未实现级联的选项 二.表准备好后就可以开始InfoPath设置了. 在设备申请表的列表选项里点击“自定义表单”.要求

GridView控件RowDataBound事件中获取列字段值的几种途径 !!!

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onclick", "javascript:alert('当前ID为:" +DataBinder.Eval(e.Row.DataItem,"CID"