简体   繁体   中英

Get Sharepoint online file structure into json file using javascript

I have a problem, I am a UX Designer and I am designing a Global Enterprise knowledge base. Data is stored everywhere. I need to be able to pull a list of directories & files from an online (hosted on Office 365) sharepoint repository and place it in a json file. Then allow the users to select the files and download them. My biggest need is to be able to get the list from the repository. I have been through the tons of documentation from MSDN, and now more confused than ever. I am strong in HTML5, CSS3, and kind-of weak in Javascript. All help is appreicated.

If you want to retrieve folders and files in a JSON format, you can use jQuery's AJAX and REST to retrieve the data.

Your folders are document libraries, which are still SharePoint lists.

$.ajax({
    url:"/_api/lists/",
    headers: { "Accept": "application/json; odata=verbose"},
    success:function(data) {
        $.each(data.d.results, function(i, item) {
            //here you can iterate through your items
            data.d.results[i].FIELDNAME;
        })
    }
});

You will still need to use filters to select only your document libraries. Your best guess might be filtering by the content type.

Here is the ODATA documentation to filter your content:

http://www.odata.org/documentation/odata-version-2-0/uri-conventions/

Once you get the list you want, here you can query a specific list:

$.ajax({
    url:"/_api/lists/getbytitle('LISTNAME')/items",
    headers: { "Accept": "application/json; odata=verbose"},
    success:function(data) {
        $.each(data.d.results, function(i, item) {
            //here you can iterate through your items
            data.d.results[i].FIELDNAME;
        })
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM