0

I'm using SP 2013. And I have a Wiki Page Library. I try to load all items from this list. I'm using the following code:

var context = new ClientContext("SiteUrl");
context.Load(context.Site);
context.ExecuteQuery();

var list = context.Web.Lists.GetByTitle("Wiki Page Library");
context.Load(list, c=>c.ItemCount);
context.ExecuteQuery();

//it gives me actual items count
//in my case it's 9 items
//Home.aspx; About.aspx; Categories.aspx; Topic.aspx etc.
var itemsLength = list.ItemCount;

var camlQuery = @"<View Scope='All'><Query></Query></View>";
var query = new SP.CamlQuery { ViewXml = camlQuery };
var items = list.GetItems(query);
context.Load(items);
context.ExecuteQuery();
//it gives a wrong result
//only one in my case
var count =  items.ToArray().Length;

And I've also checked the following caml queries: (but unfortunately it gives me the same result)

<View Scope="RecursiveAll">
    <Query>
    <QueryOptions>
        <ViewAttributes Scope="Recursive"/>
    </QueryOptions>
    </Query>
</View>

<View Scope="RecursiveAll">
    <Query>
    </Query>
</View>

And this is helpful And this is helpful

  • can you try it as var items = list.GetItems(CamlQuery.CreateAllItemsQuery()); and check ? – Gautam Sheth Nov 15 '18 at 16:38
  • @GautamSheth actually I did. Just see I've also checked the following caml queries: section. The seconds query is exactly the same with CamlQuery.CreateAllItemsQuery() – isxaker Nov 15 '18 at 16:40
1

Everything is fine with your query. Most likely it is related with files that were uploaded for the first time by another users but never checked in (you could access those files by visiting Library settings and then Manage files which have no checked in version page)

enter image description here

Even though List.ItemCount returns all the items (including checked out ones), I'm afraid there is no way retrieve those items (or files) via CSOM/REST APIs until they checked in.

  • thanks for reply. but actually i see "All files currently have a checked in version". Basically it looks like redirect. I mean when I go to Wiki Page Library, SP redirects me to specific folder which was created automatically by SP during document library creation. I have no idea what feature/setting is it. Is it connected to web setting or to docLib settings. But no matter which document library i create SP creates the specific folder automatically. And when I try to go to this document library SP redirects me to this folder. So the same behavior with caml query. Can you help me ? – isxaker Nov 15 '18 at 16:24
  • I can add some screenshots If you need. Just pm me. – isxaker Nov 15 '18 at 16:30
0
var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle('Your List Title');
var items = list.getItems(SP.CamlQuery.createAllItemsQuery());
context.load(items, 'Include(Field1, Field2, Field3)');
context.executeQueryAsync(function(){
  var en = factorItems.getEnumerator();
  while (en.moveNext()){
    var c = en.get_current();
    console.log(c.get_item('Field1'));//get field value
    console.log(c.get_fieldValues());//get object with {Field1: value1 ... etc}
  }
}, function(s,a){alert('Failed load, server says: ' + a.get_message())});

That's your basic interface. From there you can load them into an array or process them somehow. Hope it helps.

  • 2
    The code above is completely the same as mine. The problem is not all items will be selected. Wiki page library has specific items(Home.aspx) which won't be returned. Anyway thanks. – isxaker Nov 12 '18 at 19:02

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.