Skip to content

Instantly share code, notes, and snippets.

View luismanez's full-sized avatar

Luis Mañez luismanez

View GitHub Profile
@luismanez
luismanez / Program.cs
Created May 3, 2021 13:02
PnPCore sample using multiple Auth providers
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using PnP.Core.Auth;
using PnP.Core.Auth.Services.Builder.Configuration;
using PnP.Core.Services;
using PnP.Core.Services.Builder.Configuration;
@luismanez
luismanez / TenantSiteCollectionDefaultTimeZone.ps1
Created May 13, 2020 19:55
Trying to hack SharePoint Online to Configure Site Collection Tenant default timezone (context here: https://twitter.com/cann0nf0dder/status/1260607421111767042)
# THIS IS NOT WORKING. It´s raising a Bad Request response, but it might be possible with more testing
# and setting more Headers required by the API.
# You can do the Update from Admin centre, and get the request is done by the Page using Browser dev tools
#FIRST do Connect-PnPOnline to your tenant admin URL...
$url = "https://tenant-admin.sharepoint.com/"
$endpoint = "https://tenant-admin.sharepoint.com/_api/SPOInternalUseOnly.TenantAdminSettings"
$webCtx = (Get-PnPWeb).Context
Connect-PnPOnline -url $webUrl
$template = Load-PnPProvisioningTemplate -Path ".../template.xml"
$parser = New-Object OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.TokenParser($web, $template);
$template.CustomActions.SiteCustomActions |
Where-Object {$_.RegistrationId -ne $null} |
ForEach-Object {$_.RegistrationId = $parser.ParseString($_.RegistrationId)}
<pnp:CustomAction Name="MY_CA"
Title="Detail Panel Command Bar"
RegistrationId="{listid:My List Title}"
RegistrationType="List"
Location="ClientSideExtension.ListViewCommandSet.CommandBar"
ClientSideComponentId="44aceb7e-aaaa-bbbb-cccc-732a3422747c"
ClientSideComponentProperties="......" />
public class EFADALTokenCache : TokenCache
{
private ApplicationDbContext db = new ApplicationDbContext();
private string user;
private PerWebUserCache cache;
// constructor
public EFADALTokenCache(string user)
{
Web web = parentWeb.Webs.Add(newWeb);
context.ExecuteQueryRetry();
Podemos añadir el siguiente snippet:
if (template.ExtensibilityHandlers.Any())
{
// Clone Context pointing to Sub Site (needed for calling custom Extensibility Providers from the pnp template passing the right ClientContext)
string newWeburl = web.EnsureProperty(w => w.Url);
ClientContext webClientContext = context.Clone(newWeburl);
web = webClientContext.Web;
}
using (ClientContext context = PnPPartnerPackContextProvider.GetAppOnlyClientContext(parentSiteUrl))
Web parentWeb = context.Web;
Web web = parentWeb.Webs.Add(newWeb);
web.ApplyProvisioningTemplate(template, ptai);
public void Provision(
ClientContext ctx,
ProvisioningTemplate template,
ProvisioningTemplateApplyingInformation applyingInformation,
TokenParser tokenParser,
PnPMonitoredScope scope,
string configurationData)
@luismanez
luismanez / AddModernNewsPage
Created February 26, 2017 08:05
Adding a moder news page from CSOM
AuthenticationManager authManager = new AuthenticationManager();
ClientContext context =
authManager.GetSharePointOnlineAuthenticatedContextTenant(url, user, password);
var pageName = string.Format("ModernNewsPage_{0}.aspx", DateTime.Now.ToString("yyyyMMdd_HHmmss"));
List pagesLibrary = context.Web.GetListByTitle("Site Pages");
var pagesLibraryUrl = pagesLibrary.RootFolder.ServerRelativeUrl;
var newPageUrl = pagesLibraryUrl + "/" + pageName;
// execute after TypeScript task
build.rig.addPostTypescriptTask(helloWorldTask);
//execute before TypeScript task
build.rig.addBuildTasks(helloWorldTask);
//execute after all tasks
build.rig.addPostBuildTask(helloWorldTask);
//execute before all tasks