首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何调整单个DateModified项上的OneDrive属性

如何调整单个DateModified项上的OneDrive属性
EN

Stack Overflow用户
提问于 2017-05-03 03:51:56
回答 1查看 206关注 0票数 0

我能够上传一个文件使用OneDrive SDK没有问题。根据OneDrive发展中心上的信息,FileSystemInfo.DateModified是指服务看到文件的时间,而不是在本地修改文件的时间。

我试图手动将其更改为本地值,并建议将它们包含在请求中,但代码中设置的值没有固定,而是返回到PutAsync<Item>请求完成时。我做错什么了?

我的代码:

代码语言:javascript
复制
if (localfile != null)
                {
                    localprop = await localfile.GetBasicPropertiesAsync();
                    localtime = localprop.DateModified;
                    try
                    {
                        Stream syncstream = await localfile.OpenStreamForReadAsync();
                        using (syncstream)
                        {
                            var upload = await _userDrive.Drive.Special.AppRoot.ItemWithPath(filepath).Content.Request().PutAsync<Item>(syncstream);
                            upload.FileSystemInfo.LastModifiedDateTime = localtime;
                        }
                    }
                    catch (OneDriveException)
                    { }
                }

我对相同的查询:

代码语言:javascript
复制
oneDItem = await _userDrive.Drive.Special.AppRoot.ItemWithPath(filepath).Request().GetAsync();
                var oneDtime = (DateTimeOffset)oneDItem.FileSystemInfo.LastModifiedDateTime;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-11 10:09:49

如果您上传一个文件到一个驱动器,没有参数LastModifiedDateTime请求在一起,您可能不会改变修改的时间时,上传。但是可以通过更新请求更新项元数据。上传后,您可以得到您刚刚上传的项目,并更新其LastModifiedDateTime元数据。守则如下:

代码语言:javascript
复制
if (localfile != null)
{
    var localprop = await localfile.GetBasicPropertiesAsync();
    var localtime = localprop.DateModified;               
    try
    {
        Stream syncstream = await localfile.OpenStreamForReadAsync();
        using (syncstream)
        {
            DriveItem upload = await _userDrive.Me.Drive.Root.ItemWithPath("regfolder/regdata.jpg").Content.Request().PutAsync<DriveItem>(syncstream);
            DriveItem updateitem = new DriveItem() {
                  FileSystemInfo=new Microsoft.Graph.FileSystemInfo()
                  {
                      LastModifiedDateTime = localtime
                  }
            };                      
            DriveItem Updated = await _userDrive.Me.Drive.Root.ItemWithPath("regfolder/regdata.jpg").Request().UpdateAsync(updateitem); 
        }
    }
    catch (Exception ex)
    { }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43750751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档