我能够上传一个文件使用OneDrive SDK没有问题。根据OneDrive发展中心上的信息,FileSystemInfo.DateModified是指服务看到文件的时间,而不是在本地修改文件的时间。
我试图手动将其更改为本地值,并建议将它们包含在请求中,但代码中设置的值没有固定,而是返回到PutAsync<Item>请求完成时。我做错什么了?
我的代码:
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)
{ }
}我对相同的查询:
oneDItem = await _userDrive.Drive.Special.AppRoot.ItemWithPath(filepath).Request().GetAsync();
var oneDtime = (DateTimeOffset)oneDItem.FileSystemInfo.LastModifiedDateTime;发布于 2017-05-11 10:09:49
如果您上传一个文件到一个驱动器,没有参数LastModifiedDateTime请求在一起,您可能不会改变修改的时间时,上传。但是可以通过更新请求更新项元数据。上传后,您可以得到您刚刚上传的项目,并更新其LastModifiedDateTime元数据。守则如下:
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)
{ }
}https://stackoverflow.com/questions/43750751
复制相似问题