Skip to content

Instantly share code, notes, and snippets.

View gautamdsheth's full-sized avatar
:shipit:
Shipping

Gautam Sheth gautamdsheth

:shipit:
Shipping
View GitHub Profile
<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2019/03/ProvisioningSchema">
<pnp:Preferences Generator="OfficeDevPnP.Core, Version=3.9.1905.0, Culture=neutral, PublicKeyToken=null" />
<pnp:Templates ID="CONTAINER-TEMPLATE-189597059C6B4C3FB113CE057D982E8E">
<pnp:ProvisioningTemplate ID="TEMPLATE-189597059C6B4C3FB113CE057D982E8E" Version="1" BaseSiteTemplate="SITEPAGEPUBLISHING#0" Scope="RootSite">
<pnp:Theme Name="Orange" IsInverted="false" />
</pnp:ProvisioningTemplate>
</pnp:Templates>
</pnp:Provisioning>
public enum SharePointTheme
{
Teal,
Blue,
Orange,
Red,
Purple,
Green,
Gray,
DarkYellow,
@gautamdsheth
gautamdsheth / OOTBTheme.cs
Created May 18, 2019 08:52
Apply OOTB theme via CSOM
string userName = "admin@tenant.onmicrosoft.com";
string password = "<your-password>";
string siteUrl = "https://<tenant>.sharepoint.com/sites/testsite/";
using (ClientContext clientContext = new ClientContext(siteUrl))
{
SecureString securePassword = new SecureString();
foreach (char c in password.ToCharArray())
{
@gautamdsheth
gautamdsheth / SiteCollectionAppCatalogExists.cs
Created January 10, 2019 10:10
Determine if site collection app catalog exists or not
var appcatalog = clientContext.Site.RootWeb.SiteCollectionAppCatalog;
clientContext.Load(appcatalog);
clientContext.ExecuteQueryRetry();
if (appcatalog.ServerObjectIsNull)
{
// app catalog doesn't exist
}
else
{
// app catalog exists
@gautamdsheth
gautamdsheth / ListSiteCollectionAppCatalog.cs
Created January 10, 2019 09:59
Get a list of site collection app catalog enabled sites
var appCatalogSites = clientContext.Web.TenantAppCatalog.SiteCollectionAppCatalogsSites;
clientContext.Load(appCatalogSites);
clientContext.ExecuteQuery();
foreach (var site in appCatalogSites)
{
Console.WriteLine(site.AbsoluteUrl);
}
@gautamdsheth
gautamdsheth / RemoveSiteCollectionAppCatalog.cs
Created January 10, 2019 09:52
Remove a site collection app catalog using CSOM
var siteUrl = "https://<tenant-name>.sharepoint.com/sites/test"
using (ClientContext clientContext = new ClientContext(siteUrl))
{
try
{
// removes the site collection app catalog
// do note- it will disable the app catalog and not hide it from the UI
// this is a SharePoint thing, since App Catalog is basically a document library underneath
clientContext.Web.TenantAppCatalog.SiteCollectionAppCatalogsSites.Remove(siteUrl);
clientContext.ExecuteQueryRetry();
@gautamdsheth
gautamdsheth / AddSiteCollectionAppCatalog.cs
Last active January 10, 2019 09:50
Add a site collection app catalog using CSOM
var siteUrl = "https://<tenant-name>.sharepoint.com/sites/test"
using (ClientContext clientContext = new ClientContext(siteUrl))
{
try
{
// activate the site collection app catalog
clientContext.Web.TenantAppCatalog.SiteCollectionAppCatalogsSites.Add(siteUrl);
clientContext.ExecuteQueryRetry();
}
catch (Exception ex)
Connect-PnPOnline "https://tenant.sharepoint.com/sites/Test"
$webpartXML = [IO.File]::ReadAllText("C:\Users\Admin\Desktop\highlightedContentWebpart.webpart")
Add-PnPWebPartToWikiPage -ServerRelativePageUrl "/sites/Test/Pages/TestPage.aspx" -Xml $webpartXML -Row 1 -Column 1
@gautamdsheth
gautamdsheth / modernWebpartToWikiPage.ps1
Created October 15, 2018 08:59
Add OOTB Modern or SPFx webpart on Wiki Page
onnect-PnPOnline "https://tenant.sharepoint.com/sites/Test"
$webpartXML = [IO.File]::ReadAllText("C:\Users\Admin\Desktop\peopleModernWebpart.dwp")
Add-PnPWebPartToWikiPage -ServerRelativePageUrl "/sites/Test/Pages/TestPage.aspx" -Xml $webpartXML -Row 1 -Column 1
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="Microsoft.SharePoint.WebPartPages.ClientSideWebPart,
Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot Import WebPart</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">People</property>