How do I check in a file without changing the modified timestamp?

1.7k Views Asked by At

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?

2

There are 2 best solutions below

4
On

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.

1
On
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.