在LINQPad中使用以下代码,使用最新的(3.24.2008) OfficeDev SharePoint PnP SharePoint Online核心库
void Main()
{
var baseSite = "https://contoso.sharepoint.com";
var sharepointSite = "/ussdallas";
var siteUrl = $"{baseSite}{sharepointSite}";
var userEmailAddress = "nhodge@contoso.onmicrosoft.com";
var pageName = "ContosoMarketResearch.aspx";
var authenticationManager = new OfficeDevPnP.Core.AuthenticationManager();
var context = authenticationManager.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, "nhodge@contoso.onmicrosoft.com", "contoso!contoso");
var web = context.Web;
context.Load(web);
context.ExecuteQuery();
var subSite = web.GetWeb("redoctober"); // the "sub site" of the "ussdallas" site is "redoctober"
var subSitePage = subSite.AddClientSidePage(pageName, true);
subSitePage.Save();
}( AddClientSidePage()中的true强制将保存保存到SharePoint)
结果是在ussdallas的站点页面库中构建的,而不是在redoctober的站点页面库中构建的。
据我所知,从ClientContext返回的web.GetWeb()仍然被设置为父级(ussdallas) ClientContext .这就是为什么页面是在错误的Web上创建的。
看看OfficeDev SharePoint PnP Core Library的来源..。但我想不出如何“交换”上下文。我要再做一次吗?此时用户已经登录。
有什么已知的解决办法吗?
发布于 2020-08-11 09:20:41
您可以尝试通过以下方式交换上下文:
context= authenticationManager.GetSharePointOnlineAuthenticatedContextTenant(siteUrl + "/sub1", userName, password);
var subSite = context.Web;
context.Load(subSite);
context.ExecuteQuery();
var subSitePage = subSite.AddClientSidePage(pageName, true);
subSitePage.Save();https://stackoverflow.com/questions/63353833
复制相似问题