As the title says, how can I Check- in & check-out files using client object model?
-
1Hi! Can you please add a tag indicating the version of SharePoint? 2007, 2010 or 2013?Robert Lindgren– Robert Lindgren2013-12-04 07:01:43 +00:00Commented Dec 4, 2013 at 7:01
-
2sharePoint version 2010user21187– user211872013-12-04 07:13:56 +00:00Commented Dec 4, 2013 at 7:13
Add a comment
|
1 Answer
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);
}
-
1This doesn't seem to work on it's own. Do we have to call like
ctx.Execute()or something afterwards?BrainSlugs83– BrainSlugs832016-07-14 22:20:48 +00:00Commented Jul 14, 2016 at 22:20 -
1Turns 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 callctx.ExecuteQuery();.BrainSlugs83– BrainSlugs832016-07-15 00:56:31 +00:00Commented Jul 15, 2016 at 0:56 -
Additionally the
file.CheckOut()call will cause an exception to be thrown on the nextctx.ExecuteQuery();if the file is already checked out to you.BrainSlugs83– BrainSlugs832016-07-15 01:17:49 +00:00Commented Jul 15, 2016 at 1:17