我正在尝试从我的SharePointApp向HostWeb mastrepageGallery添加母版页。我修改了CHRIS O' BRIEN(http://www.sharepointnutsandbolts.com/2013/05/sp2013-host-web-apps-provisioning-files.html)中的代码,但是当我运行它时,我收到错误消息:"无法将文件配置到主机Web中。错误:未定义"。我使用JSOM(Java脚本对象模型)。 我也得到错误:"无法获取用户名。错误:来自服务器的意外响应数据。"最后一个错误也很奇怪,因为它在MasterPage之前工作得很好......
任何人都知道什么是错的?
'use strict';
window.KEM = window.KEM || {};
window.KEM.HostWebApp = function () {
var hostWebUrl,
appWebUrl,
hostWebContext,
destinationServerRelativeUrl,
destinationFileName,
// locate a file in the app web and retrieve the contents. If successful, provision to host web..
readFromAppWebAndProvisionToHost = function (appPageUrl, hostWebServerRelativeUrl, hostWebFileName) {
destinationServerRelativeUrl = hostWebServerRelativeUrl;
destinationFileName = hostWebFileName;
var req = $.ajax({
url: appPageUrl,
type: "GET",
cache: false
}).done(function (fileContents) {
if (fileContents !== undefined && fileContents.length > 0) {
uploadFileToHostWebViaCSOM(destinationServerRelativeUrl, destinationFileName, fileContents);
}
else {
alert('Failed to read file from app web, so not uploading to host web..');
}
}).fail(function (jqXHR, textStatus) {
alert("Request for page in app web failed: " + textStatus);
});
},
// 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);
},
onProvisionFileSuccess = function () {
$('#message').append('<br /><div>File provisioned in host web successfully: ' + destinationServerRelativeUrl + '/' + destinationFileName + '</div>');
setMaster('/' + destinationServerRelativeUrl + '/' + destinationFileName);
},
onProvisionFileFail = function (sender, args) {
alert('Failed to provision file into host web. Error:' + sender.statusCode);
},
// set master page on host web..
setMaster = function (masterUrl) {
var hostWeb = hostWebContext.get_web();
hostWeb.set_masterUrl(masterUrl);
hostWeb.update();
hostWebContext.load(hostWeb);
hostWebContext.executeQueryAsync(onSetMasterSuccess, onSetMasterFail);
},
onSetMasterSuccess = function () {
$('#message').append('<br /><div>Master page updated successfully..</div>');
},
onSetMasterFail = function (sender, args) {
alert('Failed to update master page on host web. Error:' + args.get_message());
},
init = function () {
var hostWebUrlFromQS = QS("SPHostUrl");
hostWebUrl = (hostWebUrlFromQS !== undefined) ? decodeURIComponent(hostWebUrlFromQS) : undefined;
var appWebUrlFromQS = QS("SPAppWebUrl");
appWebUrl = (appWebUrlFromQS !== undefined) ? decodeURIComponent(appWebUrlFromQS) : undefined;
}
return {
execute: function () {
init();
hostWebContext = new SP.ClientContext(window.KEM.AppHelper.getRelativeUrlFromAbsolute(hostWebUrl));
readFromAppWebAndProvisionToHost(appWebUrl + '/MasterPages/MasterOslo.txt', '_catalogs/masterpage', 'KEM.master');
}
}
}();
window.KEM.AppHelper = {
getRelativeUrlFromAbsolute: function (absoluteUrl) {
absoluteUrl = absoluteUrl.replace('https://', '');
var parts = absoluteUrl.split('/');
var relativeUrl = '/';
for (var i = 1; i < parts.length; i++) {
relativeUrl += parts[i] + '/';
}
return relativeUrl;
},
};
function QS(name) {
//Simplifies the code
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
$(document).ready(function () {
window.KEM.HostWebApp.execute();
});
答案 0 :(得分:0)
几周前我就注意到SharePoint托管应用程序出现了这个错误。它似乎只发生在SharePoint Online中,并且仅在启用了发布功能的主机站点上发生。
我提交了一张支持票,问题正在处理中。以下是Microsoft可能相关的最新更新:
SP6994 2014年5月28日下午5:05
扩展恢复现状: 工程师们正在继续在整个环境中部署修复程序 修复最终用户的影响。部署时间略长于 预期,并应在24小时内完成。
客户影响:受影响的客户可能会遇到间歇性问题 SharePoint Web应用程序呈现失败
解决方法:作为一种变通方法,客户可以刷新Web应用程序 直到它正确呈现。
预计解决时间:预计部署过程 在2014年5月29日星期四,UTC时间下午6:00完成。
下次更新:2014年5月29日星期四,UTC时间下午6:00
希望产品组在下次更新时解决此问题。