Code backup
This commit is contained in:
2026-05-10 16:59:01 +02:00
commit 368d6fafea
796 changed files with 315310 additions and 0 deletions
@@ -0,0 +1,70 @@
namespace Console.Office365
{
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;
using Newtonsoft.Json.Linq;
using OfficeDevPnP.Core.Entities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
CreateCustomPermissionLevel();
}
public static void CreateCustomPermissionLevel()
{
OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
string siteUrl = "https://*********.sharepoint.com/sites/communitysite";
string userName = "Sathish@*********.onmicrosoft.com";
string password = "************";
using (var clientContext = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
{
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.Load(web.AllProperties);
clientContext.Load(web.RoleDefinitions);
clientContext.ExecuteQueryRetry();
var roleDefinitions = web.RoleDefinitions;
// Get Owners Group and Remove the Permission Levels
var ownersGroupRoleAssignment = web.RoleAssignments.GetByPrincipal(clientContext.Web.AssociatedOwnerGroup);
ownersGroupRoleAssignment.RoleDefinitionBindings.RemoveAll();
ownersGroupRoleAssignment.Update();
clientContext.Load(ownersGroupRoleAssignment);
clientContext.ExecuteQuery();
// Get Full Control Role Definition
var customFullControlRoleDefinition = roleDefinitions.GetByName("MyPermissionLevelCreatedByCode");
clientContext.Load(customFullControlRoleDefinition);
clientContext.ExecuteQuery();
RoleDefinitionBindingCollection collRDB = new RoleDefinitionBindingCollection(clientContext);
collRDB.Add(roleDefinitions.GetByName("MyPermissionLevelCreatedByCode"));
// Bind the Newly Created Permission Level to Owners Group
web.RoleAssignments.Add(web.SiteGroups.GetById(ownersGroupRoleAssignment.PrincipalId), collRDB);
// Bind the Newly Created Permission Level to Owners Group
//ownersGroupRoleAssignment.RoleDefinitionBindings.Add(customFullControlRoleDefinition);
//ownersGroupRoleAssignment.Update();
clientContext.Load(ownersGroupRoleAssignment);
clientContext.ExecuteQuery();
}
}
}
}
+136
View File
@@ -0,0 +1,136 @@
var ctx = _sam.GetContext(new Uri("https://italsortbuttrio.sharepoint.com/sites/DevelopTest"));
//var ctx = _sam.GetContext(_so.GetPurchasingSite());
var docLibraryName = "DocList";
var name = "Test02";
//var web = ctx.Web;
//ctx.Load(web, w => w.Url);
//var list = web.Lists.GetByTitle(docLibraryName);
//ctx.Load(list, l => l.RootFolder, l => l.ContentTypes, l => l.Fields, l => l.ContentTypesEnabled);
//ctx.ExecuteQuery();
//list.ContentTypesEnabled = true;
//list.Update();
//if (!_cpt.ListContentTypeExist(ctx, docLibraryName, "Set di documenti"))
//{
// var documentCT = ctx.Site.RootWeb.AvailableContentTypes.GetById("0x0120D5");
// ctx.Load(documentCT);
// ctx.ExecuteQuery();
// var ctDocSet = new ContentTypeCreationInformation()
// {
// Name = "Set di documenti",
// ParentContentType = documentCT
// };
// list.ContentTypes.Add(ctDocSet);
// list.Update();
// ctx.ExecuteQuery();
//}
//var ctData = list.ContentTypes.Where(c => c.Name == "Set di documenti");
//var contentType = ctData.FirstOrDefault();
//ctx.Load(contentType);
//ctx.ExecuteQuery();
//DocumentSet.Create(ctx, list.RootFolder, name, contentType.Id);
//ctx.ExecuteQuery();
var oList = ctx.Web.Lists.GetByTitle(docLibraryName);
CamlQuery cQuery = new CamlQuery()
{
ViewXml = $"<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{name}</Value></Eq></Where></Query></View>"
};
var collection = oList.GetItems(cQuery);
ctx.Load(collection);
ctx.ExecuteQuery();
foreach (var oListItem in collection)
{
oListItem["MultiLink"] = "<a href=\"https://www.google.com\">Link1</a>" + "<a href=\"https://www.google.com\">Link2</a>" + "<a href=\"https://www.google.com\">Link3</a>";
oListItem.Update();
}
ctx.ExecuteQuery();
//----------
//
//var j = new Dictionary<string, string[]>()
//{
// { "PAL_ML", new string[] { "Note", "MultiLine", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
// //{ "PAL_DDT", new string[] { "TaxonomyFieldType", "DDT", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
//};
//var site = ctx.Site;
//ctx.Load(site, w => w.RootWeb, w => w.RootWeb.Fields);
//ctx.ExecuteQuery();
//foreach (var f in j)
//{
// var fieldXml = $"<Field Name='{f.Key}' Type='{f.Value[0]}' Description='' DisplayName='{f.Value[1]}' StaticName='{f.Key}' Group='{f.Value[2]}' Hidden='{f.Value[3]}' Required='{f.Value[4]}' Sealed='{f.Value[5]}' ShowInDisplayForm='{f.Value[6]}' ShowInEditForm='{f.Value[7]}' ShowInNewForm='{f.Value[8]}'>{f.Value[9]}</Field>";
// site.RootWeb.Fields.AddFieldAsXml(fieldXml, false, AddFieldOptions.AddToDefaultContentType);
// ctx.Load(site.RootWeb.Fields);
//}
//ctx.ExecuteQuery();
//
//----------
//var list = ctx.Web.Lists.GetByTitle(docLibraryName);
//ctx.Load(list);
//var lFields = list.Fields;
//ctx.Load(lFields);
//ctx.ExecuteQuery();
//if (lFields == null)
//{
// foreach (var field in lFields)
// {
// if (field.InternalName.Contains("PAL_Rich"))
// {
// field.ClientSideComponentProperties.
// }
// }
//}
//----------
//
//var fields = new[] { "PAL_Rich" };
//ctx.Load(ctx.Web);
//ctx.Load(ctx.Web.Fields);
//ctx.ExecuteQuery();
//var siteColumns = ctx.Web.Fields.Where(g => g.Group == "PAL Field");
//if (siteColumns != null)
//{
// foreach (var c in siteColumns)
// {
// if (c.InternalName.Contains("PAL_RDA"))
// {
// c.TypeAsString = "TaxonomyFieldType";
// ctx.ExecuteQuery();
// }
// if (c.InternalName.Contains("PAL_DDT"))
// {
// c.TypeAsString = "TaxonomyFieldType";
// ctx.ExecuteQuery();
// }
// }
//}
//
//---------
+29
View File
@@ -0,0 +1,29 @@
string[] projs = new string[] { "CT22-0029", "CT22-0031" };
foreach (var projName in projs)
{
var subProjSite = siteOptions.GetSubProjSite(projName);
var ctx = authenticationManager.GetContext(subProjSite);
var docLibName = $"Commerciale {projName}";
var web = ctx.Web;
var list = web.Lists.GetByTitle(docLibName);
ctx.Load(list);
list.BreakRoleInheritance(false, true);
ctx.ExecuteQuery();
var adGroup = web.EnsureUser("accounting@italsortbuttrio.onmicrosoft.com");
ctx.Load(adGroup);
var roleD = web.RoleDefinitions.GetByName("Contribute");
var roleDb = new RoleDefinitionBindingCollection(ctx) { roleD };
list.RoleAssignments.Add(adGroup, roleDb);
list.Update();
ctx.ExecuteQuery();
Console.WriteLine($"Done for {projName}");
}
+19
View File
@@ -0,0 +1,19 @@
void FieldDelete(clientContext ctx, string[] fieldNames)
{
foreach (var field in fieldNames)
{
var web = ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();
var field = web.Fields.GetByInternalNameOrTitle(field);
if (field != null)
{
field.SetAllowDeletion(true);
field.DeleteObject();
web.Update();
ctx.ExecuteQuery();
}
}
}