1

我正在寻找SharePoint 托管应用程序解决方案,它将将品牌文件(JS/CSS/图像) 配置到SharePoint Online/Office 365 环境中

我得到了一篇非常好的文章来实现这一点,并尝试实现如下链接所示:http ://www.sharepointnutsandbolts.com/2013/05/sp2013-host-web-apps-provisioning-files.html

该解决方案对我不起作用,并且在执行应用程序时,出现以下错误: Failed to provision file into host web. Error: Unexpected response data from server.这是给我错误的代码:

// utility method for uploading files to host web..
uploadFileToHostWebViaCSOM = function (serverRelativeUrl, filename, contents) {
    var createInfo = new SP.FileCreationInformation();
    createInfo.set_content(new SP.Base64EncodedByteArray());
    for (var i = 0; i < contents.length; i++) {

        createInfo.get_content().append(contents.charCodeAt(i));
    }
    createInfo.set_overwrite(true);
    createInfo.set_url(filename);
    var files = hostWebContext.get_web().getFolderByServerRelativeUrl(serverRelativeUrl).get_files();
    hostWebContext.load(files);
    files.add(createInfo);

    hostWebContext.executeQueryAsync(onProvisionFileSuccess, onProvisionFileFail);
}

请建议我,这段代码有什么问题?或者建议我另一种方式/参考,在其中我可以创建一个 SharePoint 托管的应用程序来配置品牌文件。

提前致谢!

4

1 回答 1

2

我将使用不同的方法来访问主机 Web 上下文,如下所示:

//first get app context, you will need it.
var currentcontext = new SP.ClientContext.get_current();
//then get host web context
var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
var hostcontext = new SP.AppContextSite(currentcontext, hostUrl);

function getQueryStringParameter(param) {
    var params = document.URL.split("?")[1].split("&");
    var strParams = "";
    for (var i = 0; i < params.length; i = i + 1) {
        var singleParam = params[i].split("=");
        if (singleParam[0] == param) {
            return singleParam[1];
        }
    }
}

以下是一些参考资料:

https://sharepoint.stackexchange.com/questions/122083/sharepoint-2013-app-create-list-in-host-web

https://blog.appliedis.com/2012/12/19/sharepoint-2013-apps-accessing-data-in-the-host-web-in-a-sharepoint-hosted-app/

http://www.mavention.com/blog/sharePoint-app-reading-data-from-host-web

http://www.sharepointnadeem.com/2013/12/sharepoint-2013-apps-access-data-in.html

此外,这里是一个如何部署母版页的示例,但是正如您在测试期间可能注意到的那样,用于获取主机 Web 上下文的方法不像视频中显示的那样工作,您应该使用我之前描述的方法。

https://www.youtube.com/watch?v=wtQKjsjs55I

最后,这是一个如何使用 CSOM 通过控制台应用程序部署品牌文件的示例,如果您足够聪明,您将能够将其转换为 JSOM。

https://channel9.msdn.com/Blogs/Office-365-Dev/Applying-Branding-to-SharePoint-Sites-with-an-App-for-SharePoint-Office-365-Developer-Patterns-and-P

于 2016-03-31T17:12:34.280 回答