如何从sharepoint列表中获取列的数据类型?

时间:2013-01-21 12:24:11

标签: sharepoint-2010

  1. 我想获取或检索特定列的数据类型 该列表在sharepoint列表中创建。

    Can you help me for doing the task?
    

2 个答案:

答案 0 :(得分:1)

请参阅SPField.Type(或SPField.TypeDisplayName)。

SPList list = web.Lists["my list"];
SPField field = list.Fields["particular"];
SPFieldType fieldType = field.Type;
string fieldTypeName = field.TypeDisplayName;

答案 1 :(得分:0)

建立Rich Bennema's answer(引用Microsoft.SharePoint.Client和Microsoft.SharePoint.Client.RunTime版本16 libriaries并使用Microsoft.SharePoint.Client名称空间):

using (ClientContext cont = new ClientContext(SharePointUrl))
{
    cont.Credentials = new SharePointOnlineCredentials(Username, SecurePassword);

    FieldCollection fields = cont.Web.Lists.GetByTitle(SharePointListName).Fields;
    cont.Load(fields);
    cont.ExecuteQuery();

    var results =
            fields.Select(
                f => new
                {
                    f.InternalName,
                    f.TypeDisplayName,
                    TextMaxLength = (f is FieldText) ? ((FieldText)f).MaxLength : 0,
                    FieldChoices = (f is FieldChoice) ? ((FieldChoice)f).Choices : new string[0]
                }
            );
}