I try to get familiar with with the Javascript API of SharePoint 2013 (Preview). Therefore I started a SharePoint-hosted app using VS2012. The default app works just great after deploying to my local SharePoint 2013.

Now I try to get access to the documents of that SharePoint instance using Javascript but I couldn't find an point to get started for this in the API documentation. Any hint what namespace / functions / etc. use to get access to documents would be great.

For example: "How many documents are in the library or a given view etc.?"

Thx, Marc

2 Answers 2


So what you would want to do is have a look at the JavaScript Client Object Model (2013). It has all the classes for the functionality you want to achieve.

A great link to start with it is here:


And here is a complete reference of the JavaScript API:


  • Thanks. I found that already. Its about website properties, list and listitems. I am looking for accessing the document-library but can't find that stuff in any reference. Maybe I am looking for the wrong keywords. Are documents stored in list-items or is this something different?
    – Marc
    Commented Sep 3, 2012 at 6:06
  • Yes documents are indeed stored as list items. You will have to use SP.ListItem.get_file(); to get the file properties of the document. msdn.microsoft.com/en-us/library/ee552478 This link is of the SP2010 Client Object Model but it should work in the 2013 version too. Commented Sep 3, 2012 at 6:20
  • ah ok. that makes sense now. thx!
    – Marc
    Commented Sep 3, 2012 at 7:22

Instead of using CSOM from JavaScript you may find it a lot easier to use the REST api

To get information about a document library you may use: http://sp2013srv/_api/web/lists/getByTitle('Documents')

To only get the number of documents use: http://sp2013srv/_api/web/lists/getByTitle('Documents')?$select=ItemCount

To get list of items to see properties use: http://sp2013srv/_api/web/lists/getByTitle('Documents')/Items

To get file info about a single item use: http://sp2013srv/_api/web/lists/getByTitle('Documents')/Items(1)/File

Amongst the properties is the ServerRelativeUrl you can use to get the file.

To work through folder you can use: http://sp2013srv/_api/web/lists/getByTitle('Documents')/RootFolder

And continue down through: http://sp2013srv/_api/web/lists/getByTitle('Documents')/RootFolder/Files or http://sp2013srv/_api/web/lists/getByTitle('Documents')/RootFolder/Folders

  • The REST API is indeed great but I feel it is more useful if you are programming on a non-windows platform. Also, batch processing and the ability to program against objects make me lean more on the side of the JSCOM. I would suggest @Marc to have a look at the following link to determine what API is right for you: msdn.microsoft.com/en-us/library/… Commented Aug 31, 2012 at 18:51
  • Are files/documents (Default Installation > Menu > "Documents") stored in list-items so I need to use the list's API?
    – Marc
    Commented Sep 3, 2012 at 6:08
  • I see an advantage for the REST API on Windows-Platforms too: I'd like to use ASP.Net MVC for my provider-hosted app. Have to try that but maybe REST is an easy alternative to .Net library which is not by default supported in MVC.
    – Marc
    Commented Sep 3, 2012 at 6:10

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.