Skip to content

Instantly share code, notes, and snippets.

View AsishP's full-sized avatar

Asish Padhy AsishP

  • Sydney, Australia
View GitHub Profile
using (var ctx = new ClientContext(<site url>))
{
ctx.RequestTimeout = Timeout.Infinite;
Web web = ctx.Web;
ctx.Load(web, w => w.Title);
ctx.ExecuteQueryRetry();
ProvisioningTemplateApplyingInformation ptai
= new ProvisioningTemplateApplyingInformation
{
using (Context ctx = new ClientContext(<siteUrl>))
{
string TemplateFilename = "<FileName>.xml";
ctx.Load(ctx.Web, w => w.Lists, w => w.Folders);
Microsoft.SharePoint.Client.File templateFile = ctx.Web.Lists.GetByTitle("Site Assets").RootFolder.Folders.GetByUrl("Templates").GetFile(TemplateFilename);
ctx.ExecuteQuery();
FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(ctx, templateFile.ServerRelativeUrl);
assetContext.ExecuteQuery();
filePath = Path.GetTempPath() + "\\" + TemplateFilename;
using (var fileStream = new FileStream(filePath, FileMode.Create))
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core.Sites;
using (ClientContext ctx = new ClientContext(<TenantAdminUrl>))
{
// create new "modern" team site at the url
// https://[tenant].sharepoint.com/sites/mymodernteamsite
string alias = taskParam.TargetWebUrl.Substring(Url.LastIndexOf('/') + 1);
using OfficeDevPnP.Core.Framework.Graph;
using Microsoft.Graph;
using Microsoft.SharePoint.Client;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
var authenticationContext = new AuthenticationContext(authString, false);
// Config for OAuth client credentials
ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
AuthenticationResult authenticationResult = null;
string token = "";
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.DocumentManagement;
// Replace all instances of < > with your variables
using (var context = new ClientContext(<siteUrl>))
{
context.Credentials = new SharePointOnlineCredentials(UserName, SecurePass);
listToOperate = context.Web.GetListByUrl(<listRelUrl>);
context.Load(listToOperate);
context.ExecuteQuery();
using (var contextNavigation = new ClientContext(<siteURL>))
{
contextNavigation.Credentials = new SharePointOnlineCredentials(UserName, SecurePass);
Web web = contextNavigation.Web;
contextNavigation.Load(web, w => w.Navigation);
contextNavigation.Load(web);
contextNavigation.ExecuteQuery();
//Start working on Navigation
NavigationNodeCollection lefthandNav = web.Navigation.QuickLaunch;
//Check the gist code - https://gist.github.com/AsishP/b817455ce58b753e4f02ae5a0482e7a4 for filling the NavIds Array
foreach (int id in navIds)
{
NavigationNode nodeToDelete = web.Navigation.GetNodeById(id);
contextAsset.Load(nodeToDelete);
contextAsset.ExecuteQuery();
nodeToDelete.DeleteObject();
contextAsset.ExecuteQuery();
}
using (var context = new ClientContext(<siteURL>))
{
contextAsset.Credentials = new SharePointOnlineCredentials(UserName, SecurePass);
Web web = contextAsset.Web;
contextAsset.Load(web, w => w.Navigation);
contextAsset.Load(web);
contextAsset.ExecuteQuery();
//Start working on Navigation
NavigationNodeCollection lefthandNav = web.Navigation.QuickLaunch;
return processComplete
? req.CreateResponse(HttpStatusCode.OK, "Success")
: req.CreateResponse(HttpStatusCode.Accepted, "Error");
UnifiedGroupsUtility.UpdateUnifiedGroup(group.GroupId, token, groupLogo: <logo url>,
members:<Members email array>, isPrivate: <boolean>, retryCount: <numberofretries>);