Google Drive Document Time Stamp

2019-02-11 00:56发布

问题:

I assume that the modifiedDate search field is the date of modification (obviously) or upload to the drive. Is there a way to preserve the original creation date of the file on its native system? Or is there a possibility to modify this field? Thank you, Sean

回答1:

You can use File.Update to set the modification date after upload.

https://developers.google.com/drive/v2/reference/files/update

Also, File.Patch works too:

https://developers.google.com/drive/v2/reference/files/patch

I know that I read another old thread sometime where it was discussed that it would be nice to be able to preserve the original creation date on insert, or at least to have that as an option, but this functionality does not exist yet. (Can't find the post now...)

UPDATE:

I decided it would be nice to have a method to update the document time stamp, so here it is:

    public static File SetLastModified(string fileID, DateTime lastModified)
    {
        File file = DriveService.Files.Get(fileID).Fetch();
        file.ModifiedDate = lastModified.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fff'Z'");
        try
        {
            FilesResource.UpdateRequest request = DriveService.Files.Update(file, fileID);
            request.SetModifiedDate = true;
            file = request.Fetch();
        }
        catch (Exception e)
        {
            throw;
        }
        return file;
    }