Create a context dynamically by Url, not predefined in PnpCoreOptions.Sites #1627
-
We have a huge number of Sharepoint sites (not subsites/subwebs). With CSOM I could open the sites by just passing the Url. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
From the readme
using (var scope = host.Services.CreateScope())
{
var pnpContextFactory = scope.ServiceProvider.GetRequiredService<IPnPContextFactory>();
var pnpAuthenticationProviderFactory = scope.ServiceProvider.GetRequiredService<IAuthenticationProviderFactory>();
var interactiveAuthProvider = pnpAuthenticationProviderFactory.Create("interactive");
var passwordManagerAuthProvider = pnpAuthenticationProviderFactory.Create("usernamepassword");
using (var context = await pnpContextFactory.CreateAsync(new Uri("https://contoso.sharepoint.com/sites/prov-1"),
interactiveAuthProvider))
{
await context.Web.LoadAsync(p => p.Title);
Console.WriteLine($"The title of the web is {context.Web.Title}");
using (var context2 = await pnpContextFactory.CreateAsync(new Uri("https://contoso.sharepoint.com/sites/prov-1"),
passwordManagerAuthProvider))
{
await context2.Web.LoadAsync(p => p.Title);
Console.WriteLine($"The title of the web is {context2.Web.Title}");
}
}
} |
Beta Was this translation helpful? Give feedback.
From the readme