0

I want to checkin and publish all the files inside a folder and its sub-folders

Below is my code

private void checkinFile(ClientContext ctx, string foldername) {
            ctx.Load(ctx.Web, a => a.Lists);
            ctx.ExecuteQuery();
            List list = ctx.Web.Lists.GetByTitle(foldername);
            var files = list.GetItems(
                new CamlQuery()
                {
                    ViewXml = @"<View Scope='RecursiveAll'><Query> 
            <Where><IsNotNull><FieldRef Name='CheckoutUser' /></IsNotNull></Where> 
            </Query></View>"
                });
            ctx.Load(files);
            ctx.ExecuteQuery();
            foreach (var file in files)
            {
                file.File.CheckIn("Add", CheckinType.MajorCheckIn);
                Console.WriteLine("-----------------------");
                Console.WriteLine("");
            }

        }

Usage package.checkinFile(ctx, "Style Library");

This is not publishing/check-in the files the style library sub folders

1 Answer 1

1

Found out the issue

I missed to add the ctx.executequery

So the below code works fine

private void checkinFile(ClientContext ctx, string foldername) {
            ctx.Load(ctx.Web, a => a.Lists);
            ctx.ExecuteQuery();
            List list = ctx.Web.Lists.GetByTitle(foldername);
            var files = list.GetItems(
                new CamlQuery()
                {
                    ViewXml = @"<View Scope='RecursiveAll'><Query> 
            <Where><IsNotNull><FieldRef Name='CheckoutUser' /></IsNotNull></Where> 
            </Query></View>"
                });
            ctx.Load(files);
            ctx.ExecuteQuery();
            foreach (var file in files)
            {
                file.File.CheckIn("Add", CheckinType.MajorCheckIn);
                Console.WriteLine("-----------------------");
                Console.WriteLine("");
            }
            ctx.ExecuteQuery();
        }

I thought of deleting the question since it hasn't got answers from others, but then I couldnt find this snippet in SO and I thought this might help someone in future

2
  • 1
    Please accept your solution as answer. so that it will helpful for other users
    – TARUN
    May 23, 2017 at 12:19
  • sure Tarun will do looks like I can accept my answer only after 2 days :) May 23, 2017 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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