EcmaScript Client Object Model : How to get the list of items/files/folders of the current user?
The code snippet below shows how to retrieve the currently logged in user and to retrieve his documents/folders or listitems/folders according to the type of list you're working with:
The first things you need to do is to prepare the objects such as ClientContext, the current web & site, the current user (get_currentUser()), then you load them and you call your first asynchroneous execution.
Once executed, all the objects are populated with their medatadata. In OnLoadQuerySucess, you can prepare your CAML query that's recursively taking all the items of the currently logged in user.
You need to load the resulting item collection this way :
this.ClientContext.load(this.CollListItem,'Include(DisplayName, ContentType, File, Id, Created, Modified)');
The Include keyword is very important because we tell SharePoint that we want to retrieve some metadata such as DisplayName, Id, Created and Modified and that we plan to work with the SPFile and SPContentType objects. If you don't include those, you won't be able to perform operations such as SPFile.get_name().
At last, the third part is to iterate through the returned item collection and to display the output. You'll notice that the following calls ContentType.get_name(), File.get_timeCreated() etc... were only made possible by the prior inclusion above.
Here is the result of the above on a list containing one document :
I'll soon publish a new tool on http://sptoolbasket2010.codeplex.com/ with a new toolbar associated to every type of list.