【问题标题】:How to provision Branding files using SharePoint Hosted App in SharePoint Online/Office 365?如何在 SharePoint Online/Office 365 中使用 SharePoint Hosted App 配置品牌文件?
【发布时间】:2016-07-19 10:28:51
【问题描述】:

我正在寻找 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 托管的应用程序来配置品牌文件。

提前致谢!

【问题讨论】:

  • 是否有更多信息(例如内部异常)提供有关实际货币意外响应的更多详细信息?
  • @Ola :我试图获取堆栈跟踪,但它给了我空值。我只收到相同的消息,使用args.get_message()。除了get_message(), args.get_errorTraceCorrelationId(),其余参数为空
  • 您最初是否配置了 .txt 扩展名?

标签: sharepoint office365 sharepoint-online sharepoint-apps sharepoint-jsom


【解决方案1】:

我将使用不同的方法来访问主机 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

【讨论】:

    猜你喜欢
    • 2019-01-08
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多