是否可以通过CSOM以编程方式在Provider Hosted中添加应用程序? [英] Is possible add an app programmatically via CSOM in Provider Hosted?
问题描述
大家好,
在本地的Sharepoint 2013中,我已在应用程序目录"中安装了该应用程序. (contoso.com/sites/catalog/),现在我想通过代码CSOM在其他网站集中添加一个应用.
In Sharepoint 2013 on premises I have the app installed in "app Catalog" (contoso.com/sites/catalog/) , now I want add an app in other site collection through code CSOM.
通过用户界面非常简单.
网站内容->添加应用->点击应用->相信它.
Through the user interface is very simple.
Site content -> Add an App -> Click on the app -> Trust It.
我的代码在下面,但不起作用.
My code is below but not working.
var url= new Uri("contoso.com/sites/working/");
var accessToken = TokenHelper.GetS2SAccessTokenWithWindowsIdentity(url, null);
using (var clientContext = TokenHelper.GetClientContextWithAccessToken(url.AbsoluteUri, accessToken))
{
Web web= clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
var appIstances = AppCatalog.GetAppInstances(clientContext, webCatalog);
var appInstance = AppCatalog.GetAppInstance(clientContext, webCatalog, new Guid("583F4F4E-7473-4337-9BF5-00E2A8A48E48"));
appInstance.Install();
clientContext.Load(appInstance);
clientContext.ExecuteQuery();
}
谢谢
推荐答案
请尝试使用'new ClientContext("siteurl'")'获得客户端上下文.
Please try to get client context using 'new ClientContext("siteurl")'.
检查以下类似的线程:
https://sharepoint.stackexchange.com/questions/104221/add-an -app-through-csom
最好的问候,
这篇关于是否可以通过CSOM以编程方式在Provider Hosted中添加应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!