0

I tried to create a RESTful call that can be invoked by Angular/JavaScript command to load all data from a csv file or json file and dump them in javascript arrays

I tried

https://my.sharepoint.com/site/_api/Web/lists/getbytitle('Documents')/items

From returned contents it is able to find items but nothing regarding file name. but file id like

<id>a03b9f92-abcd-49d8-abcd-d75838917649</id>

And if I use

https://my.sharepoint.com/site/_api/Web/lists/GetFileByServerRelativeUrl('/site/Documents/data.csv')/files

it returned 'Cannot find resource for the request GetFileByServerRelativeUrl'

Is there a better way to load data file from library to javascript object?

PS: the reason I have to use document is because SharePoint list has limit of 20k rows. I have a lot rows to load.

1 Answer 1

2

You can use the REST API "/_api/Web/GetFileByServerRelativeUrl('/sites/mysite/test/JS File.js')/$value"to read data from js/csv files in the Document Library.

An example:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

<script type="text/javascript">
    $(function () {
        // begin work to call across network
        var requestUri = _spPageContextInfo.webAbsoluteUrl +
                      "/_api/Web/GetFileByServerRelativeUrl('/sites/mysite/test/JS File.js')/$value";

        // execute AJAX request
        $.ajax({
            url: requestUri,
            type: "GET",
            headers: { "ACCEPT": "application/json;odata=verbose" },
            success: function (data) {                 
                alert(data);
            },
            error: function () {
                alert("Failed to get details");
            }
        });
    });
</script>

My test result:

enter image description here

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.