简体   繁体   English

执行 SaveBinaryDirect 后如何覆盖 SharePoint 的修改日期?

[英]How to Overwrite SharePoint's Modified Date after Doing a SaveBinaryDirect?

I can push a file to SharePoint, but the modified date is always equal to the exact time I uploaded it.我可以将文件推送到 SharePoint,但修改日期始终等于我上传的确切时间。 How can I overwrite the modified date to be equal to the value of the file?如何覆盖修改后的日期以等于文件的值? The code below was my failing guess after many searches.下面的代码是我多次搜索后的失败猜测。

Using "TimeLastModified" seems to error as non-existent while "Modified" seems to not error but the subsequent ExecuteQuery then gives an unknown error.使用“TimeLastModified”似乎不存在错误,而“Modified”似乎没有错误,但随后的 ExecuteQuery 会给出未知错误。

    using (var ctx = new ClientContext(DataSharepointSite))
    {
        ctx.AuthenticationMode = ClientAuthenticationMode.Default;
        ctx.Credentials = GetCreds();
        using (FileStream fs = new FileStream(localFile, FileMode.Open))
        {
            Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, sharepointFile, fs, true);
        }

        //****************
        // Now somehow set Modified Date to local File's Modified Date
        //****************
        var file = ctx.Web.GetFileByServerRelativeUrl(sharepointFile);
        ListItem lstItem = file.ListItemAllFields;
        ctx.Load(lstItem);
        ctx.ExecuteQuery();
        lstItem["TimeLastModified"] = System.IO.File.GetLastWriteTime(localFile).ToUniversalTime();
        lstItem.Update();
        ctx.ExecuteQuery();
    }

I was so close.我是如此接近。 Looks like the Load and first ExecuteQuery were also not needed.看起来也不需要 Load 和 first ExecuteQuery。 Now I just don't know if it's read as local or UTC...现在我只是不知道它是读作本地还是 UTC ......

lstItem["Modified"] = System.IO.File.GetLastWriteTime(localFile).ToUniversalTime().ToString();

Try the code snippet to update Modified field:尝试使用代码片段更新 Modified 字段:

        var file = ctx.Web.GetFileByServerRelativeUrl(sharepointFile);
        ListItem lstItem = file.ListItemAllFields;
        ctx.Load(lstItem);
        ctx.ExecuteQuery();
        lstItem["Modified"] = System.IO.File.GetLastWriteTime(localFile).ToShortDateString();
        lstItem.Update();
        ctx.ExecuteQuery();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 SaveBinaryDirect (C#) 将文件上传到 SharePoint Online 时出现 401 错误 - 401 Error When Uploading File to SharePoint Online with SaveBinaryDirect (C#) 在SharePoint:CreatedModifiedInfo中为“上次修改”修改日期格式 - Modify Date Format for “last modified” in SharePoint:CreatedModifiedInfo Sharepoint客户端GetFolderByServerRelativeUrl文件夹的修改日期 - Sharepoint client GetFolderByServerRelativeUrl folder modified date 保存更改后如何设置修改的最新日期 - How to set the latest date modified after saving changes Retain Modified Date During SharePoint (online) 文件传输使用ClientContext - Retain Modified Date During SharePoint (online) File Transfers Using ClientContext 覆盖 SharePoint 文件而不丢失其版本历史记录 - Overwrite SharePoint file without loosing it's version history 复制文件后修改日期未更新 - Modified date is not updating after copying files 如何在ASP.NET Core MVC中获取文件的最后修改日期? - How to get a file's last modified date in ASP.NET Core MVC? Amazon S3,同步,修改日期与上载日期 - Amazon S3, Syncing, Modified date vs. Uploaded Date 如何捕获Sharepoint中的过期信息? - How to capture date out in sharepoint?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM