Microsoft.SharePoint.Client在线FieldType映射

时间:2018-02-21 18:52:11

标签: sharepoint mapping fieldtype

我正在尝试将值推送到SharePoint Online列表中。 几个问题:

  1. 如果我使用SharePoint在线结构创建此代码,是否也适用于拥有自己的内部部署服务器的公司?或者我是否必须创建一个全新的代码库来支持它?似乎SPFieldTypeFieldType之间存在一些巨大差异,或者代码会自动进行更改吗?
  2. 在映射FieldType中,我正在寻找一些参考或代码来解释各种字段类型的正确映射。我已经在姐妹产品SharePoint 2013中看到了这些内容,例如:
  3. https://social.technet.microsoft.com/wiki/contents/articles/21801.sharepoint-a-complete-guide-to-getting-and-setting-fields-using-c.aspx

    但2013 SPFieldTypeMicrosoft.SharePoint.Client.FieldType之间的差异似乎相当大。是否有相应的内容描述了每个字段类型在FieldType

    中取得成功所需的值

    以下是我现有代码的示例,以及我仍然缺少的内容:

           public string ToString(Microsoft.SharePoint.Client.FieldType ColumnType)
        {
            switch (ColumnType)
            {
                case Microsoft.SharePoint.Client.FieldType.Boolean:
                    // 0 or 1, or "true" or "false"???
                    break;
                case Microsoft.SharePoint.Client.FieldType.Calculated:
                    // No idea!
                    break;
                case Microsoft.SharePoint.Client.FieldType.Choice:
                    // No idea!
                    break;
                case Microsoft.SharePoint.Client.FieldType.Computed:
                    // No idea!
                    break;
                case Microsoft.SharePoint.Client.FieldType.Currency:
                    // No idea!
                    break;
                case Microsoft.SharePoint.Client.FieldType.DateTime:
                    return GetDateTimeValue().ToString("yyyy-MM-dd");
    
                case Microsoft.SharePoint.Client.FieldType.File:
                    // No idea!
                    break;
                case Microsoft.SharePoint.Client.FieldType.GridChoice:
                    // No idea!
                    break;
                case Microsoft.SharePoint.Client.FieldType.Guid:
                    // No idea!
                    break;
                case Microsoft.SharePoint.Client.FieldType.Integer:
                    return GetIntValue().ToString(); 
    
                case Microsoft.SharePoint.Client.FieldType.Lookup:
                    // No idea!
                    break;
                case Microsoft.SharePoint.Client.FieldType.MultiChoice:
                    // No idea!
                    break;
                case Microsoft.SharePoint.Client.FieldType.Note:
                    return GetStringValue();
                case Microsoft.SharePoint.Client.FieldType.Number:
                    return GetDoubleValue().ToString();
                case Microsoft.SharePoint.Client.FieldType.Text:
                    return GetStringValue();
                case Microsoft.SharePoint.Client.FieldType.User:
                    // No idea!
                    break;
                case Microsoft.SharePoint.Client.FieldType.URL:
                    // No idea!
                    break;
                // No Idea what to do for these
                case Microsoft.SharePoint.Client.FieldType.WorkflowEventType:
                case Microsoft.SharePoint.Client.FieldType.WorkflowStatus:
                case Microsoft.SharePoint.Client.FieldType.AllDayEvent:
                case Microsoft.SharePoint.Client.FieldType.Attachments:
                case Microsoft.SharePoint.Client.FieldType.ThreadIndex:
                case Microsoft.SharePoint.Client.FieldType.Threading:
                case Microsoft.SharePoint.Client.FieldType.PageSeparator:
                case Microsoft.SharePoint.Client.FieldType.Recurrence:
                case Microsoft.SharePoint.Client.FieldType.Invalid:
                case Microsoft.SharePoint.Client.FieldType.ContentTypeId:
                case Microsoft.SharePoint.Client.FieldType.Counter:
                case Microsoft.SharePoint.Client.FieldType.CrossProjectLink:
                case Microsoft.SharePoint.Client.FieldType.MaxItems:
                case Microsoft.SharePoint.Client.FieldType.ModStat:
                case Microsoft.SharePoint.Client.FieldType.Error:
                    break;
                default:
                    return GetStringValue();
            }
            return GetStringValue();
        }
    

    缺少的方法只是将数据中的值转换为适当的字符串。

1 个答案:

答案 0 :(得分:1)

服务器对象模型和.NET客户端对象模型不同。 如果您想将值推送到SharePoint Online List,我建议您使用Pnp-PowerShell来实现它。

Add-PnPListItem

关于字段类型,请检查GetField中的代码。

如果您不想使用Pnp-PowerShell,则需要将服务器对象模型代码转换为客户端对象模型代码。