如何在单个 OneDrive 项目上调整 DateModified 属性
How to adjust DateModified property on a single OneDrive item
我可以使用 OneDrive SDK 上传文件,没问题。根据 OneDrive Dev Center 上的信息,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;
如果您upload a file to one drive, there is no parameter for LastModifiedDateTime
to request together, you may not change the modified time when uploading. But you can update an item metadata by update请求。上传后,您可以获取刚刚上传的项目并更新其 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)
{ }
}
我可以使用 OneDrive SDK 上传文件,没问题。根据 OneDrive Dev Center 上的信息,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;
如果您upload a file to one drive, there is no parameter for LastModifiedDateTime
to request together, you may not change the modified time when uploading. But you can update an item metadata by update请求。上传后,您可以获取刚刚上传的项目并更新其 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)
{ }
}