Skip to content

Instantly share code, notes, and snippets.

@sksnips
Created May 16, 2016 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sksnips/7e1f437dda0b97d080e3cb182e0fe18b to your computer and use it in GitHub Desktop.
Save sksnips/7e1f437dda0b97d080e3cb182e0fe18b to your computer and use it in GitHub Desktop.
This code snippet used to create a website using PnP Core Component - CSOM Extensions
//Author: Shantha Kumar T
// Assembly Reference Used: OfficeDevPnP.Core, Version=2.4.1605.0, Culture=neutral, PublicKeyToken=3751622786b357c2
//Supports: SharePoint Online, SharePoint 2013+
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;
namespace SampleApplication
{
class Program
{
static void Main(string[] args)
{
string siteUrl = "https://sharepointonline.sharepoint.com";
bool isInheritPermissions = false;
bool isInheritNavigation = false;
AuthenticationManager authManager = new AuthenticationManager();
//Interactive Login to SharePoint site - Opens a Online signin page to authenticate the user
var context = authManager.GetWebLoginClientContext(siteUrl);
Web web = context.Site.RootWeb.CreateWeb(
new OfficeDevPnP.Core.Entities.SiteEntity()
{
Title = "Sample Site",
Url = "samplesite",
Description = "Site creating for testing purpose",
Template = "STS#0",
Lcid = 1033
}, isInheritPermissions, isInheritNavigation);
Console.WriteLine(web.Title + " site created successfully!");
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}
//OUTPUT:
//Sample Site site created sucessfully!
//Press any key to exit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment