1

我找的SharePoint託管的應用解決方案這將提供品牌文件(JS/CSS /圖片)爲的SharePoint Online/Office 365的環境如何在SharePoint Online/Office 365中使用SharePoint託管應用程序設置品牌文件?

我有一個很好的文章,以實現這一目標,並試圖實現相同如下圖所示鏈接: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託管的應用程序以配置品牌文件。

在此先感謝!

+0

有一些像內部異常的詳細信息是提供什麼實際的金錢意想不到的反應更多的細節? –

+0

@Ola:我試圖獲取堆棧跟蹤,但它給了我空值。我只使用'args.get_message()'獲得相同的消息。其餘參數爲空,除了'get_message(),args.get_errorTraceCorrelationId()' –

+0

你是否已經預備了一個.txt擴展名? –

回答

2

我會用不同的方法來訪問主機網絡的上下文如下:

//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

相關問題