update
This commit is contained in:
@@ -23,9 +23,9 @@ namespace SharePointOnlineUtils
|
|||||||
string svcUser = "svcItsSharePointAdmin@italsort.com";
|
string svcUser = "svcItsSharePointAdmin@italsort.com";
|
||||||
SecureString svcUserPsw = new NetworkCredential("", "$O,D1XBp1O5.OdjZt86#a=").SecurePassword;
|
SecureString svcUserPsw = new NetworkCredential("", "$O,D1XBp1O5.OdjZt86#a=").SecurePassword;
|
||||||
|
|
||||||
//ProjectsByYearSite(siteCollection, svcUser, svcUserPsw);
|
ProjectsByYearSite(siteCollection, svcUser, svcUserPsw);
|
||||||
Project(siteCollection, svcUser, svcUserPsw);
|
Project(siteCollection, svcUser, svcUserPsw);
|
||||||
//SubProject(siteCollection, svcUser, svcUserPsw);
|
SubProject(siteCollection, svcUser, svcUserPsw);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task ProjectsByYearSite(string siteCollection, string user, SecureString psw)
|
public static async Task ProjectsByYearSite(string siteCollection, string user, SecureString psw)
|
||||||
@@ -38,7 +38,6 @@ namespace SharePointOnlineUtils
|
|||||||
using (var authMgr = new AuthenticationManager())
|
using (var authMgr = new AuthenticationManager())
|
||||||
using (var ctx = authMgr.GetContext(site, user, psw))
|
using (var ctx = authMgr.GetContext(site, user, psw))
|
||||||
{
|
{
|
||||||
//SharePointCustomOperation.ProjectsYQuickMenu(ctx);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (SharePointCustomOperation.SiteExist(ctx) == false)
|
if (SharePointCustomOperation.SiteExist(ctx) == false)
|
||||||
@@ -63,7 +62,7 @@ namespace SharePointOnlineUtils
|
|||||||
string year = DateTime.Now.Year.ToString();
|
string year = DateTime.Now.Year.ToString();
|
||||||
string projectsYear = $"Commesse{year}";
|
string projectsYear = $"Commesse{year}";
|
||||||
string listTitle = $"Lista Commesse {year}";
|
string listTitle = $"Lista Commesse {year}";
|
||||||
string ssProjectTitle = "CT0014";
|
string ssProjectTitle = "CT0001";
|
||||||
|
|
||||||
Uri site = new Uri($"{siteCollection}/sites/{projectsYear}");
|
Uri site = new Uri($"{siteCollection}/sites/{projectsYear}");
|
||||||
Uri subSite = new Uri($"{siteCollection}/sites/{projectsYear}/{ssProjectTitle}");
|
Uri subSite = new Uri($"{siteCollection}/sites/{projectsYear}/{ssProjectTitle}");
|
||||||
@@ -73,19 +72,17 @@ namespace SharePointOnlineUtils
|
|||||||
using (var ctx = authMgr.GetContext(site, user, psw))
|
using (var ctx = authMgr.GetContext(site, user, psw))
|
||||||
{
|
{
|
||||||
//if (SharePointCustomOperation.SiteExist(ctx)) //TODO: Controllo if sub site exist
|
//if (SharePointCustomOperation.SiteExist(ctx)) //TODO: Controllo if sub site exist
|
||||||
//SharePointCustomOperation.ProjectSubSite(ssProjectTitle, projectsYear, ctx);
|
SharePointCustomOperation.ProjectSubSite(ssProjectTitle, projectsYear, ctx);
|
||||||
//SharePointCustomOperation.ProjectListEntry(ssProjectTitle, listTitle, projectsYear, ctx);
|
SharePointCustomOperation.ProjectListEntry(ssProjectTitle, listTitle, projectsYear, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var authMgr = new AuthenticationManager())
|
using (var authMgr = new AuthenticationManager())
|
||||||
using (var ctx = authMgr.GetContext(subSite, user, psw))
|
using (var ctx = authMgr.GetContext(subSite, user, psw))
|
||||||
{
|
{
|
||||||
//SharePointCustomOperation.ProjectDocLib(ssProjectTitle, ctx);
|
SharePointCustomOperation.ProjectDocLib(ssProjectTitle, ctx);
|
||||||
// edit short cut menu + set SottoProgetti view a homepage
|
SharePointCustomOperation.ProjectSubProjListField(ssProjectTitle, ctx);
|
||||||
//SharePointCustomOperation.ProjectSubProjListField(ssProjectTitle, ctx);
|
|
||||||
//SharePointCustomOperation.ProjectSubProjListView(ssProjectTitle, ctx);
|
|
||||||
SharePointCustomOperation.ProjectSubProjListView(ssProjectTitle, ctx);
|
SharePointCustomOperation.ProjectSubProjListView(ssProjectTitle, ctx);
|
||||||
|
SharePointCustomOperation.ProjectQuickMenu(ssProjectTitle, subSite.ToString(), ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +91,8 @@ namespace SharePointOnlineUtils
|
|||||||
string year = DateTime.Now.Year.ToString();
|
string year = DateTime.Now.Year.ToString();
|
||||||
string projectsYear = $"Commesse{year}";
|
string projectsYear = $"Commesse{year}";
|
||||||
string listTitle = $"Lista Commesse {year}";
|
string listTitle = $"Lista Commesse {year}";
|
||||||
string ssProjectTitle = "CT0014";
|
string ssProjectTitle = "CT0001";
|
||||||
string[] ssSubProjectTitle = { "CT0015-0001", "CT0015-0002", "CT0015-0003" };
|
string[] ssSubProjectTitle = { "CT0001-0001", "CT0001-0002", "CT0001-0003" };
|
||||||
|
|
||||||
Uri subSite = new Uri($"{siteCollection}/sites/{projectsYear}/{ssProjectTitle}");
|
Uri subSite = new Uri($"{siteCollection}/sites/{projectsYear}/{ssProjectTitle}");
|
||||||
|
|
||||||
@@ -116,6 +113,7 @@ namespace SharePointOnlineUtils
|
|||||||
public string DeliveryReason { get; set; }
|
public string DeliveryReason { get; set; }
|
||||||
public List<SubProj> SubProjects { get; set; }
|
public List<SubProj> SubProjects { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SubProj
|
public class SubProj
|
||||||
{
|
{
|
||||||
public string ProjId { get; set; }
|
public string ProjId { get; set; }
|
||||||
@@ -129,7 +127,6 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class SharePointCustomOperation
|
public class SharePointCustomOperation
|
||||||
{
|
{
|
||||||
#region Check If Exist
|
#region Check If Exist
|
||||||
@@ -348,9 +345,8 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
wci.Url = ssProjectTitle;
|
wci.Url = ssProjectTitle;
|
||||||
wci.Title = ssProjectTitle;
|
wci.Title = ssProjectTitle;
|
||||||
|
|
||||||
wci.UseSamePermissionsAsParentSite = true;
|
wci.UseSamePermissionsAsParentSite = true;
|
||||||
wci.WebTemplate = "STS#1";
|
wci.WebTemplate = "SITEPAGEPUBLISHING#0";
|
||||||
wci.Language = 1040;
|
wci.Language = 1040;
|
||||||
|
|
||||||
Web web = ctx.Site.RootWeb.Webs.Add(wci);
|
Web web = ctx.Site.RootWeb.Webs.Add(wci);
|
||||||
@@ -397,7 +393,7 @@ namespace SharePointOnlineUtils
|
|||||||
#region DocLib
|
#region DocLib
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string[] docLibName = { $"Commerciale {ssProjectTitle}", $"Documenti {ssProjectTitle}", $"Media {ssProjectTitle}", $"SottoProgetti {ssProjectTitle}" };
|
string[] docLibName = { $"Commerciale {ssProjectTitle}", $"Documenti {ssProjectTitle}", $"Media {ssProjectTitle}", $"SottoCommesse {ssProjectTitle}" };
|
||||||
|
|
||||||
foreach (string libName in docLibName)
|
foreach (string libName in docLibName)
|
||||||
{
|
{
|
||||||
@@ -412,27 +408,6 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
if (libName == $"SottoProgetti {ssProjectTitle}")
|
|
||||||
{
|
|
||||||
list.ContentTypesEnabled = true;
|
|
||||||
list.AddContentTypeToListByName("Set di documenti");
|
|
||||||
|
|
||||||
list.Update();
|
|
||||||
ctx.ExecuteQuery();
|
|
||||||
}
|
|
||||||
|
|
||||||
var fld = list.Fields.GetByInternalNameOrTitle(libName);
|
|
||||||
if (fld != null)
|
|
||||||
{
|
|
||||||
fld.Required = false;
|
|
||||||
fld.SetShowInDisplayForm(false);
|
|
||||||
fld.SetShowInEditForm(false);
|
|
||||||
fld.SetShowInNewForm(false);
|
|
||||||
|
|
||||||
list.Update();
|
|
||||||
ctx.ExecuteQuery();
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"> '{libName}' è stato creato con successo.");
|
Console.WriteLine($"> '{libName}' è stato creato con successo.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -480,28 +455,28 @@ namespace SharePointOnlineUtils
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task ProjectSubProjListField(string ssProjectTitle, ClientContext ctx) // Empty Da definire i campi che userà ITS
|
public static async Task ProjectSubProjListField(string ssProjectTitle, ClientContext ctx)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine($"> Inizializzata la fase di creazione dei campi in 'SottoProgetti {ssProjectTitle}'.");
|
Console.WriteLine($"> Inizializzata la fase di creazione dei campi in 'SottoCommesse {ssProjectTitle}'.");
|
||||||
|
|
||||||
Web web = ctx.Web;
|
Web web = ctx.Web;
|
||||||
List list = web.Lists.GetByTitle($"SottoProgetti {ssProjectTitle}");
|
List list = web.Lists.GetByTitle($"SottoCommesse {ssProjectTitle}");
|
||||||
List projectsList = web.Lists.GetByTitle($"SottoProgetti {ssProjectTitle}");
|
List projectsList = web.Lists.GetByTitle($"SottoCommesse {ssProjectTitle}");
|
||||||
|
|
||||||
ctx.Load(list, l => l.Fields);
|
ctx.Load(list, l => l.Fields);
|
||||||
ctx.Load(projectsList, b => b.Id);
|
ctx.Load(projectsList, b => b.Id);
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
Field lookupItemField = list.Fields.AddFieldAsXml(@"<Field Type='Text' Name='PAL_Item' StaticName='PAL_Item' DisplayName='Item' Required='FALSE' />", true, AddFieldOptions.DefaultValue);
|
Field lookupItemField = list.Fields.AddFieldAsXml(@"<Field Type='Text' Name='PAL_Item' StaticName='PAL_Item' DisplayName='Item' Required='FALSE' />", true, AddFieldOptions.DefaultValue);
|
||||||
Field lookupArticleNumberField = list.Fields.AddFieldAsXml(@"<Field Type='Text' Name='PAL_ArticleNumber' StaticName='PAL_ArticleNumber' DisplayName='Codice Articolo' Required='FALSE' />", true, AddFieldOptions.DefaultValue); // item cod
|
Field lookupArticleNumberField = list.Fields.AddFieldAsXml(@"<Field Type='Text' Name='PAL_ItemCode' StaticName='PAL_ItemCode' DisplayName='Codice Articolo' Required='FALSE' />", true, AddFieldOptions.DefaultValue);
|
||||||
Field lookupArticleDescriptionField = list.Fields.AddFieldAsXml(@"<Field Type='Text' Name='PAL_ArticleDescription' StaticName='PAL_ArticleDescription' DisplayName='Descrizione Articolo' Required='FALSE' />", true, AddFieldOptions.DefaultValue);
|
Field lookupArticleDescriptionField = list.Fields.AddFieldAsXml(@"<Field Type='Text' Name='PAL_ItemDescription' StaticName='PAL_ItemDescription' DisplayName='Descrizione Articolo' Required='FALSE' />", true, AddFieldOptions.DefaultValue);
|
||||||
Field lookupMachineSerialNumberField = list.Fields.AddFieldAsXml(@"<Field Type='Text' Name='PAL_MachineSerialNumber' StaticName='PAL_MachineSerialNumber' DisplayName='Matricola Macchina' Required='FALSE' />", true, AddFieldOptions.DefaultValue);
|
Field lookupMachineSerialNumberField = list.Fields.AddFieldAsXml(@"<Field Type='Text' Name='PAL_SerialNumber' StaticName='PAL_SerialNumber' DisplayName='Matricola Macchina' Required='FALSE' />", true, AddFieldOptions.DefaultValue);
|
||||||
|
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
Console.WriteLine($"> Completata la fase di creazione dei campi in 'SottoProgetti {ssProjectTitle}'.");
|
Console.WriteLine($"> Completata la fase di creazione dei campi in 'SottoCommesse {ssProjectTitle}'.");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -513,7 +488,7 @@ namespace SharePointOnlineUtils
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var listTitle = $"SottoProgetti {ssProjectTitle}";
|
var listTitle = $"SottoCommesse {ssProjectTitle}";
|
||||||
Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{listTitle}'.");
|
Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{listTitle}'.");
|
||||||
|
|
||||||
List list = ctx.Web.Lists.GetByTitle(listTitle);
|
List list = ctx.Web.Lists.GetByTitle(listTitle);
|
||||||
@@ -549,6 +524,39 @@ namespace SharePointOnlineUtils
|
|||||||
Console.WriteLine($"> Qualcosa è andato storto nella creazione della ListView. ( {ex.Message} )");
|
Console.WriteLine($"> Qualcosa è andato storto nella creazione della ListView. ( {ex.Message} )");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task ProjectQuickMenu(string ssProjectTitle, string subSiteUrl, ClientContext ctx)
|
||||||
|
{
|
||||||
|
Dictionary<string, string> itemQuickMenu = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ $"Commerciale {ssProjectTitle}", $"{subSiteUrl}/Commerciale%20{ssProjectTitle}" },
|
||||||
|
{ $"Documenti {ssProjectTitle}", $"{subSiteUrl}/Documenti%20{ssProjectTitle}" },
|
||||||
|
{ $"Media {ssProjectTitle}", $"{subSiteUrl}/Media%20{ssProjectTitle}" },
|
||||||
|
{ $"SottoCommesse {ssProjectTitle}", $"{subSiteUrl}/SottoCommesse%20{ssProjectTitle}" }
|
||||||
|
};
|
||||||
|
|
||||||
|
NavigationNodeCollection spNavNodeColl = ctx.Web.Navigation.QuickLaunch;
|
||||||
|
NavigationNodeCreationInformation newNavNode = new NavigationNodeCreationInformation();
|
||||||
|
|
||||||
|
ctx.Load(ctx.Web);
|
||||||
|
|
||||||
|
foreach (KeyValuePair<string, string> item in itemQuickMenu)
|
||||||
|
{
|
||||||
|
|
||||||
|
newNavNode.Title = item.Key;
|
||||||
|
newNavNode.Url = item.Value;
|
||||||
|
newNavNode.AsLastNode = true;
|
||||||
|
spNavNodeColl.Add(newNavNode);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
Console.WriteLine($"> Il menu rapido è stato aggiornato in {ssProjectTitle}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{ Console.WriteLine($"> Qualcosa è andato storto... ( {ex.Message} )"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SubProject
|
#region SubProject
|
||||||
@@ -556,13 +564,27 @@ namespace SharePointOnlineUtils
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (string spt in ssSubProjectTitle)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"> Inizializzata la fase di creazione per {spt}.");
|
|
||||||
|
|
||||||
#region List Context
|
#region Context
|
||||||
var list = ctx.Web.Lists.GetByTitle($"SottoProgetti {ssProjectTitle}");
|
var list = ctx.Web.Lists.GetByTitle($"SottoCommesse {ssProjectTitle}");
|
||||||
ctx.Load(list, l => l.RootFolder, l => l.ContentTypes, l => l.Fields);
|
ctx.Load(list, l => l.RootFolder, l => l.ContentTypes, l => l.Fields, l => l.ContentTypesEnabled);
|
||||||
|
ctx.ExecuteQuery();
|
||||||
|
list.ContentTypesEnabled = true;
|
||||||
|
list.Update();
|
||||||
|
|
||||||
|
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();
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
var ctData = list.ContentTypes.Where(c => c.Name == "Set di documenti");
|
var ctData = list.ContentTypes.Where(c => c.Name == "Set di documenti");
|
||||||
@@ -571,7 +593,12 @@ namespace SharePointOnlineUtils
|
|||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
foreach (string spt in ssSubProjectTitle)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"> Inizializzata la fase di creazione per {spt}.");
|
||||||
|
|
||||||
#region DocSet & Field value
|
#region DocSet & Field value
|
||||||
|
|
||||||
DocumentSet.Create(ctx, list.RootFolder, spt, contentType.Id);
|
DocumentSet.Create(ctx, list.RootFolder, spt, contentType.Id);
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
|
|
||||||
@@ -581,9 +608,9 @@ namespace SharePointOnlineUtils
|
|||||||
|
|
||||||
dsItem["_ExtendedDescription"] = "valueDescription";
|
dsItem["_ExtendedDescription"] = "valueDescription";
|
||||||
dsItem["Item"] = "valueItem";
|
dsItem["Item"] = "valueItem";
|
||||||
dsItem["Codice_x0020_Articolo"] = "valueArticleNumber";
|
dsItem["Codice_x0020_Articolo"] = "valueItemCode";
|
||||||
dsItem["Descrizione_x0020_Articolo"] = "valueArticleDescription";
|
dsItem["Descrizione_x0020_Articolo"] = "valueItemDescription";
|
||||||
dsItem["Matricola_x0020_Macchina"] = "valueMachineSerialNumber";
|
dsItem["Matricola_x0020_Macchina"] = "valueSerialNumber";
|
||||||
|
|
||||||
dsItem.Update();
|
dsItem.Update();
|
||||||
ctx.ExecuteQuery();
|
ctx.ExecuteQuery();
|
||||||
@@ -606,7 +633,7 @@ namespace SharePointOnlineUtils
|
|||||||
Console.WriteLine($"Le sotto cartelle sono state create con successo in {spt}");
|
Console.WriteLine($"Le sotto cartelle sono state create con successo in {spt}");
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
Console.WriteLine($"> {spt} creato con successo in SottoProgetti {ssProjectTitle}.");
|
Console.WriteLine($"> {spt} creato con successo in SottoCommesse {ssProjectTitle}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -614,7 +641,6 @@ namespace SharePointOnlineUtils
|
|||||||
Console.WriteLine($"> Qualcosa è andato storto... ( {ex.Message} )");
|
Console.WriteLine($"> Qualcosa è andato storto... ( {ex.Message} )");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user