【问题标题】:SharePoint 2016 Checkin using C# - FileNotFound ExceptionSharePoint 2016 使用 C# 签入 - FileNotFoundException
【发布时间】:2019-10-02 18:40:17
【问题描述】:

我正在使用以下代码使用 C# 将文件签入到 SharePoint 2016。但它抛出 Microsoft.SharePoint.Client.ServerException: File Not Found. 文件 URL 有效,并且在控制台中打印 file.name 以确认其有效性。请告知这里出了什么问题。

            string url = "valid url of the file";
            var file = clientContext.Web.GetFileByServerRelativeUrl(url);
            clientContext.Load(file);
            clientContext.ExecuteQuery();
            Console.WriteLine(file.Name); //successfully printed expected result
            file.CheckIn("Test", CheckinType.MajorCheckIn);
            clientContext.Load(file);
            clientContext.ExecuteQuery(); //File Not Found Exception thrown at this point

【问题讨论】:

  • 为什么要在上下文中加载文件两次?
  • 即使在我删除加载后,它也无法正常工作并引发同样的错误。

标签: c# sharepoint automation sharepoint-2016


【解决方案1】:

试试这个:

using (ClientContext clientContext = GetContextObject())
{
    string url = "valid url of the file";
    var file = clientContext.Web.GetFileByServerRelativeUrl(url);

    using (FileStream fs = new FileStream(file, FileMode.Open))
    {
        File.SaveBinaryDirect(clientContext, file, fs, true);
    }
}

【讨论】:

  • 它没有抛出异常并保存文件。但是,文件仍然没有签入。这是最终目标,它没有发生:(
【解决方案2】:

您可能会发现“文件的有效 url”实际上是无效的。我从一个“有效”的 URL 中收到此错误,即从浏览器打开 Sharepoint 中的文件,但我认为文件名包含 C# CSOM 接口不支持的某些字符。在我的情况下,该文件名为“GetPDF.aspx%2F4AA3-8247ENW.pdf”,所以可能是因为它有两个句点,但我很难确认。

【讨论】:

    【解决方案3】:

    你可以看看https://www.codesharepoint.com/csom/get-checkin-comment-of-file-in-sharepoint-using-csom。我从未使用过 CSOM 和 GetFileByServerRelativeUrl,但我似乎记得 CheckIn 必须发生在文件上,而不是包含文件的项目上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      • 2017-07-26
      相关资源
      最近更新 更多