1

I am using the SharePoint CSOM with a C# desktop application and am trying to check-in a file to a document library that has the "Require check out" setting enabled. I want the modified timestamp to stay the same (not updated).

After the check-in, I update the list item with the original timestamp. This works when "Require check out" is disabled, but when it is enabled, I get an exception that says the file must be checked out first. I have tried updating the list item before the check-in, but it gets overwritten when the check-in occurs.

Is there any way to do this?

Steve
  • 165
  • 1
  • 13
  • see this - https://microsofttouch.fr/english/b/vince365/posts/systemupdate-method-available-in-csom-at-last if you update to a newer csom you should be able to do it – Ctznkane525 Aug 21 '18 at 00:23

2 Answers2

0
lstItem.Update()
lstItem.SystemUpdate()

You can use update to update the files and the modified dates. System update will update the file without changing the modified dates.

JMyner
  • 61
  • 8
  • It's the check-in that causes the modified timestamp to be updated. Once the file is checked in, I can't change the modified timestamp because it isn't checked out. Keep in mind, the "Require checkout" setting is enabled on the document library. – Steve Aug 21 '18 at 11:08
0

After you use SystemUpdate to update the data, have you tried OverwriteCheckin when you're checking the SPFile back in?

listItem.SystemUpdate();    
file.CheckIn("comment", CheckinType.OverwriteCheckIn);

Edit: After you clarified you're not working with drafts, I recommend you use SPFile.UndoCheckOut() to discard the checkout programmatically. Otherwise you're inherently going against the design of SharePoint by modifying content without marking the content as modified.

Jim Yarbro
  • 2,063
  • 15
  • 21
  • I have not, but my understanding from this [post](https://social.msdn.microsoft.com/Forums/sharepoint/en-US/dda8f456-902e-484c-9ed6-4cec7db9e035/overwritecheckin-not-working?forum=sharepointdevelopmentlegacy) is this is only supposed to be used when you are checking in a draft. – Steve Aug 21 '18 at 13:24
  • If you're not working with drafts, then you are either a) trying to discard a checkout, or b) trying to update the content of files. If a, then use `SPFile.UndoCheckOut()`. If b, then you're inherently going against the design of SharePoint as content being updated constitutes modification. – Jim Yarbro Aug 22 '18 at 05:30
  • I am updating file contents. Is there a way to update the modified and modified by fields after the file is checked in if the "Require checkout" setting is enabled? Is there any way around having to check out the file? – Steve Aug 22 '18 at 17:42
  • Try setting the `ReadOnly` property on the Modified field to false, then change it before the `SystemUpdate` – Jim Yarbro Aug 24 '18 at 04:46