0

I have successfully embedded javascipt with jQuery into a page in SharePoint and I am trying to write a function that, when called on load, obtains the data from an excel file that has been uploaded into the SharePoint's library, so that I can manipulate it with JavaScript and push it into a SharePoint List. My issues are coming from that first part. I have attempted to do this with the following code, which was obtained from SharePoint's documentation and modified to use the ".fail" function instead of the deprecated ".error" function:

function readFile() {
    var clientContext;
    var oWebsite;
    var fileUrl;

    clientContext = new SP.ClientContext.get_current();
    oWebsite = clientContext.get_web();

    clientContext.load(oWebsite);
    clientContext.executeQueryAsync(function () {
        fileUrl = "My file's url as obtained from SharePoint";

        $.ajax({
            url: fileUrl,
            type: "GET"
        })
            .done(Function.createDelegate(this, successHandler))
            .fail(Function.createDelegate(this, errorHandler));
    }, errorHandler);

    function successHandler(data) {
        console.log(data);
    }

    function errorHandler() {
        console.log("Request failed: " + arguments[2]);
    }
}

This appears to work, as I receive no errors and the data is indeed displayed in the console. However, instead of the file's contents, I see this:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name='viewport' content='width=device-width, initial-scale=1' />
    <meta name='robots' content='noindex' />
    <link rel="shortcut icon" href="http://spoos-16-rdn.bankofamerica.com/wv/resources/1033/FavIcon_Word.ico" />
    <title>Document.docx</title>

    <script type="text/javascript">
       var WOPIPerf_UserClick = null;
       if (window.sessionStorage)
       {
           WOPIPerf_UserClick = window.sessionStorage.getItem("WOPIPerf_UserClickTime");
           window.sessionStorage.removeItem("WOPIPerf_UserClickTime");
       }
    </script>

    <script type="text/javascript">
function ULS6zp(){var o=new Object;o.ULSTeamName="Microsoft SharePoint Foundation";o.ULSFileName="WOPIFrame.aspx";return o;}
        function getWopiIFrameElement()
        {ULS6zp:;
            return document.querySelector("iframe[name=WebApplicationFrame]");
        }
        function WACRedirector()
        {ULS6zp:;
            var myFrame = getWopiIFrameElement();
            myFrame.id = "WebAp

I'm not sure what's going on, but I feel like there's a step missing here. When I enter the url into my browser, it redirects to SharePoint's in-house document editor, where I can indeed see the document's contents and even edit it. Is there something else I need to do to obtain the file's actual content in JavaScript?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.