-
Finally have some time to get a POC of using this together and am real curious about... "Sites": { This is concerning given our use case in which the consumer of the sdk will have a massive, ever changing list of sites. It appears a lot like I could just send in whatever site I want for this, which would be great and makes my concern moot/makes me real curious why it's there. using (var context = await pnpContextFactory.CreateAsync("SiteToWorkWith")) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@tbithell , sorry for the late response, GitHub discussions don't show a number on top, so I missed this one. This also works: using (var context = await pnpContextFactory.CreateAsync(new Uri("https://contoso.sharepoint.com/sites/prov-1")))
{
// do things
} You actually do not even need a config file, below is a minimal setup without config file: class Program
{
public static async Task Main(string[] args)
{
var host = Host.CreateDefaultBuilder()
// Configure PnP services
.ConfigureServices((hostingContext, services) =>
{
services.AddPnPCore(options =>
{
options.DefaultAuthenticationProvider = new InteractiveAuthenticationProvider(
"<appid>",
"contoso.onmicrosoft.com",
new Uri("http://localhost"));
});
})
// Let the builder know we're running in a console
.UseConsoleLifetime()
// Add services to the container
.Build();
await host.StartAsync();
var pnpContextFactory = host.Services.GetRequiredService<IPnPContextFactory>();
using (var context = await pnpContextFactory.CreateAsync(new Uri("https://contoso.sharepoint.com/sites/hr")))
{
await context.Web.LoadAsync(p => p.Title);
Console.WriteLine($"Web title = {context.Web.Title}");
}
host.Dispose();
}
} |
Beta Was this translation helpful? Give feedback.
@tbithell , sorry for the late response, GitHub discussions don't show a number on top, so I missed this one.
This also works:
You actually do not even need a config file, below is a minimal setup without config file: