4

As the title says, how can I Check- in & check-out files using client object model?

  • Hi! Can you please add a tag indicating the version of SharePoint? 2007, 2010 or 2013? – Robert Lindgren Dec 4 '13 at 7:01
  • 1
    sharePoint version 2010 – user21187 Dec 4 '13 at 7:13
7

To check-out:

//get the connection
ClientContext ctx = new ClientContext("http://sitename");

//get the home page
File home = ctx.Web.GetFileByServerRelativeUrl("/SitePages/home.aspx");
ctx.load(home);
//check whether file is already checkout. If not then only do the checkout. 
if (home.CheckOutType == CheckOutType.None)
{
   home.CheckOut();
}

To check-in:

//Only checkin if the file is already checkout. 
if (home.CheckOutType != CheckOutType.None)
{
   home.CheckIn(string.Empty, CheckinType.MajorCheckIn);
}
  • This doesn't seem to work on it's own. Do we have to call like ctx.Execute() or something afterwards? – BrainSlugs83 Jul 14 '16 at 22:20
  • Turns out the check-in is not performed until call ctx.ExecuteQuery(); -- further, if the file is not checked out, this will totally throw an exception when you call ctx.ExecuteQuery();. – BrainSlugs83 Jul 15 '16 at 0:56
  • Additionally the file.CheckOut() call will cause an exception to be thrown on the next ctx.ExecuteQuery(); if the file is already checked out to you. – BrainSlugs83 Jul 15 '16 at 1:17

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.