0

We have a requirement to automatically check in uploaded documents. I used this article to implement an event viewer that would perform this action. But when this is deployed to the site, we noticed that the Checked Out To field still displays the account name that added the document. Any suggestions as what method can be used to clear the checked out to field on adding a document?

Code snippet:

using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace CustomItemAdded.EventReceiver1 { public class EventReceiver1 : SPItemEventReceiver { public override void ItemAdded(SPItemEventProperties properties) { base.ItemAdded(properties); SPFile thisFile = properties.ListItem.File;

if (!thisFile.CheckOutType.Equals(SPFile.SPCheckOutType.None)) { thisFile.CheckIn("Checked in by custom event handler."); } } }

}

Thanks!

  • 1
    can you provide your code where you programmatically check in? – Gwny Oct 7 '14 at 14:13
  • The code is in the URL provided in the question. I did not make any other changes to it. – SP2013 Oct 7 '14 at 19:16
  • That link seems really unstable, care to add the code to your post? – Robert Lindgren Oct 7 '14 at 19:22
  • Robert Lindgren, hope that helps! – SP2013 Oct 8 '14 at 6:07
0

The response in this URL resolved my issue. ItemAdded is an asynchronous event by default, so even though the document is checked in, document properties were not being updated simultaneously. ItemAdding on the other hand is synchronous but it is not possible to check in a document in that event as the content is not accessible until after ItemAdded is fired.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.