【问题标题】:Posting metadata to sharepoint 2016 onpremise : System.Text.DecoderFallbackException with special characters将元数据发布到 sharepoint 2016 onpremise :带有特殊字符的 System.Text.DecoderFallbackException
【发布时间】:2017-07-03 21:56:06
【问题描述】:

我尝试在 SharePoint 列表中创建包含元数据的项目。 其中一个元数据包含一个法语“ç”字符,它使共享点响应 500 错误,其中: 代码=-1,System.Text.DecoderFallbackException value=无法将索引 147 处的 Unicode 字符 [E7] 转换为指定的代码页。

using (var client = new SpWebClient("https://intranet/Gestion") { Credentials = CurrentNetworkCredential })
            {
                var payload = new JObject
                {
                    ["__metadata"] = new JObject { ["type"] = "SP.Data.ListeCommentaireGerantListItem" },
                    ["Language"] = "Français (France)"
                };

                var requestUrl = $"/_api/web/lists/GetByTitle('{SHAREPOINT_LIST}')/items";
                Dictionary<string, string> updateHeaders = null;

                var r = client.ExecuteJsonWithDigest(requestUrl, "POST", updateHeaders, payload);
                return Redirect("/");
            }

spWebClient 定义为here,基本上它添加了所有需要的标头并在webclient 类中简化了身份验证。

我尝试在标题中添加“application/json; odata=verbose;charset=utf-8”,但同样的错误。

有什么帮助吗?

【问题讨论】:

    标签: c# rest sharepoint


    【解决方案1】:

    尝试通过WebClient.Encoding Property 显式设置UTF8 发布和获取字符串的编码:

    client.Encoding = System.Text.Encoding.UTF8;
    

    示例

    using (var client = new SPWebClient("https://contoso.sharepoint.com") { Credentials = credentials, Encoding = System.Text.Encoding.UTF8 })
    {
        //the remaining code goes here...
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-01
      • 2018-04-09
      • 1970-01-01
      • 2014-03-03
      相关资源
      最近更新 更多