koltyakov / gosip

⚡️ SharePoint SDK for Go
https://go.spflow.com
MIT License
145 stars 33 forks source link

How to change the TimeLastModified of a file #45

Closed jh-chrysos closed 3 years ago

jh-chrysos commented 3 years ago

Hello,

Apologies, as I know this is probably not a bug. I am unfamiliar with the sharepoint API and thus I'm not sure of the approach to take with the gosip API. I am trying to modify a file's modification time after upload:

fileAddResp, err := folder.Files().Add(w.name, p, true)

I can see the property and modify it:

fileAddResp.Data().TimeLastModified = w.modTime

But I am not sure how to apply that modification back to sharepoint (or even if that is possible).

It might be a nice addition to the https://go.spflow.com/samples/documents page under "Adding/uploading a file".

Thank you for building this framework - it's already been tremendously useful!

koltyakov commented 3 years ago

Hey @jh-chrysos,

Updating the data which is received from the API won't update anything in SharePoint obviously , it's a local struct in memory not something which would represent an observable for a remote calls on its mutation.

Please check items updating docs. However, Modified field in file's item is a system one and is not allowed for updates, it is updated automatically with file/item changes on a server. Yet, there is a trick. If the account which is user for the API authentication is the site admin they can update an item in a "system update" mode using UpdateValidate

jh-chrysos commented 3 years ago

Thank you for the information!