From 60f11dd91c6a92c626949b97d8e31f90451b8566 Mon Sep 17 00:00:00 2001
From: Kalarumeth <70245579+Kalarumeth@users.noreply.github.com>
Date: Thu, 28 Jul 2022 11:40:24 +0200
Subject: [PATCH] Added field on SitePage
Update DevExpress
---
console_spo_utils/Program.cs | 146 ++++++++----------
...console_spo_utils.csproj.nuget.dgspec.json | 3 +
.../console_spo_utils.csproj.nuget.g.props | 3 +-
console_spo_utils/obj/project.assets.json | 4 +
4 files changed, 75 insertions(+), 81 deletions(-)
diff --git a/console_spo_utils/Program.cs b/console_spo_utils/Program.cs
index a43995d..346f53d 100644
--- a/console_spo_utils/Program.cs
+++ b/console_spo_utils/Program.cs
@@ -58,11 +58,10 @@ namespace SharePointOnlineUtils
Uri subSite = new Uri($"{siteCollection}/sites/{projectsYear}/{ssProjectTitle}");
#endregion
- SharePointCustomOperation.ProjectsYField();
- //ProjectsByYearSite(listTitle, year, svcUser, site, svcUserPsw);
- //Project(siteCollection, svcUser, svcUserPsw);
- //SubProject(siteCollection, svcUser, svcUserPsw);
+ ProjectsByYearSite(listTitle, year, svcUser, site, svcUserPsw);
+ Project(siteCollection, svcUser, svcUserPsw);
+ SubProject(siteCollection, svcUser, svcUserPsw);
}
public static async Task ProjectsByYearSite(string listTitle, string year, string user, Uri site, SecureString psw)
@@ -70,12 +69,12 @@ namespace SharePointOnlineUtils
using (var authMgr = new AuthenticationManager())
using (var ctx = authMgr.GetContext(site, user, psw))
{
+
if (SharePointCustomOperation.SiteExist(ctx) == false)
{
SharePointCustomOperation.ProjectsYSite(year, site, user, psw);
- //SharePointCustomOperation.ProjectsYField(ctx);
+ SharePointCustomOperation.ProjectsYField(ctx);
SharePointCustomOperation.ProjectsYList(listTitle, ctx);
- SharePointCustomOperation.ProjectsYListField(listTitle, ctx);
SharePointCustomOperation.ProjectsYListView(listTitle, ctx);
}
}
@@ -262,25 +261,28 @@ namespace SharePointOnlineUtils
ctx.Load(site, w => w.RootWeb, w => w.RootWeb.Fields);
ctx.ExecuteQuery();
+ string xmlChoice = "01 VENDITA MACCHINE / IMPIANTI02 VENDITA RICAMBI04 VENDITA SERVIZI FUORI COMMESSA08 VENDITA RIPARAZIONI09 ENGINEERING11 VENDITA E LAVORAZ.CONTO TERZI55 PREVENDITENC NON CONFORMITÁ";
+
Dictionary fieldList = new Dictionary()
{
- { "PAL_ID_Project", new string[] { "Url", "ID Progretto", "", "", "", "", "", "", "", "", "", "" } },
- { "PAL_DlvReason", new string[] { "Choice", "", "", "", "", "", "", "", "", "", "", "" } },
- { "PAL_Customer", new string[] { "Text", "", "", "", "", "", "", "", "", "", "", "" } },
- { "PAL_Item", new string[] { "Text", "", "", "", "", "", "", "", "", "", "", "" } },
- { "PAL_ItemCode", new string[] { "Text", "", "", "", "", "", "", "", "", "", "", "" } },
- { "PAL_ItemDescription", new string[] { "Text", "", "", "", "", "", "", "", "", "", "", "" } },
- { "PAL_SerialNumber", new string[] { "Text", "", "", "", "", "", "", "", "", "", "", "" } }
+ { "PAL_ID_Project", new string[] { "URL", "ID Progetto", "PAL Field", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
+ { "PAL_DlvReason", new string[] { "Choice", "Causale", "PAL Field", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", xmlChoice } },
+ { "PAL_Customer", new string[] { "Text", "Cliente", "PAL Field", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
+ { "PAL_Item", new string[] { "Text", "Item", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
+ { "PAL_ItemCode", new string[] { "Text", "Codice Articolo", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
+ { "PAL_ItemDescription", new string[] { "Text", "Descrizione Articolo", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
+ { "PAL_SerialNumber", new string[] { "Text", "Matricola Macchina", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } }
};
- //"01 VENDITA MACCHINE / IMPIANTI02 VENDITA RICAMBI04 VENDITA SERVIZI FUORI COMMESSA08 VENDITA RIPARAZIONI09 ENGINEERING11 VENDITA E LAVORAZ.CONTO TERZI55 PREVENDITENC NON CONFORMITÁ"
+
foreach (KeyValuePair f in fieldList)
{
- var fieldXml = $"{f.Value[11]}";
+ var fieldXml = $"{f.Value[9]}";
site.RootWeb.Fields.AddFieldAsXml(fieldXml, false, AddFieldOptions.AddToDefaultContentType);
ctx.Load(site.RootWeb.Fields);
- ctx.ExecuteQuery();
}
+
+ ctx.ExecuteQuery();
}
catch (Exception ex)
{ Console.WriteLine($"> Qualcosa è andato storto... ( {ex.Message} )"); }
@@ -323,57 +325,36 @@ namespace SharePointOnlineUtils
}
}
- public static async Task ProjectsYListField(string listTitle, ClientContext ctx)
- {
- try
- {
- Console.WriteLine($"> Inizializzata la fase di creazione dei campi '{listTitle}'.");
-
- Web web = ctx.Web;
- List list = web.Lists.GetByTitle(listTitle);
- List projectsList = web.Lists.GetByTitle(listTitle);
-
- ctx.Load(list, l => l.Fields);
- ctx.Load(projectsList, b => b.Id);
- ctx.ExecuteQuery();
-
- string idProjField = @"";
- Field lookupIdProjField = list.Fields.AddFieldAsXml(idProjField, true, AddFieldOptions.DefaultValue);
-
- string clientField = @"";
- Field lookupClientField = list.Fields.AddFieldAsXml(clientField, true, AddFieldOptions.DefaultValue);
-
- string dlvReasonField = @""
- + ""
- + " 01 VENDITA MACCHINE / IMPIANTI"
- + " 02 VENDITA RICAMBI"
- + " 04 VENDITA SERVIZI FUORI COMMESSA"
- + " 08 VENDITA RIPARAZIONI"
- + " 09 ENGINEERING"
- + " 11 VENDITA E LAVORAZ.CONTO TERZI"
- + " 55 PREVENDITE"
- + " NC NON CONFORMITÁ"
- + ""
- + "";
- Field lookupDlvReasonField = list.Fields.AddFieldAsXml(dlvReasonField, true, AddFieldOptions.DefaultValue);
-
- ctx.ExecuteQuery();
-
- Console.WriteLine($"> Completata la fase di creazione dei campi '{listTitle}'.");
- }
- catch (Exception ex)
- {
- Console.WriteLine($"> Qualcosa è andato storto nella creazione delle colonne. ( {ex.Message} )");
- }
- }
-
public static async Task ProjectsYListView(string listTitle, ClientContext ctx)
{
try
{
- Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{listTitle}'.");
+ #region Field
+ Console.WriteLine($"> Inizializzata la fase di importazione dei campi '{listTitle}'.");
List list = ctx.Web.Lists.GetByTitle(listTitle);
+ var siteField = ctx.Site.RootWeb;
+ ctx.Load(list, l => l.Fields);
+ ctx.Load(siteField, s => s.Fields);
+
+ ctx.ExecuteQuery();
+
+ string[] fieldName = { "ID Progetto", "Cliente", "Causale" };
+
+ foreach (var fn in fieldName)
+ {
+ var Fields = siteField.Fields.GetByTitle(fn);
+ list.Fields.Add(Fields);
+ }
+
+ ctx.ExecuteQuery();
+
+ Console.WriteLine($"> Completata la fase di importazione dei campi '{listTitle}'.");
+ #endregion
+
+ #region View
+ Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{listTitle}'.");
+
var views = list.Views;
@@ -383,7 +364,7 @@ namespace SharePointOnlineUtils
viewCreation.Title = listTitle;
viewCreation.ViewTypeKind = ViewType.None;
viewCreation.ColumnWidth = "350";
- viewCreation.ViewFields = new string[3] { "ID Progetto", "Cliente", "Causale" };
+ viewCreation.ViewFields = new string[] { "ID Progetto", "Cliente", "Causale" };
var view = views.Add(viewCreation);
@@ -407,6 +388,8 @@ namespace SharePointOnlineUtils
ctx.ExecuteQuery();
Console.WriteLine($"> Impostata come HomePage di '{viewCreation.Title}'");
+ #endregion
+
}
catch (Exception ex)
{
@@ -454,9 +437,9 @@ namespace SharePointOnlineUtils
link.Url = $"/sites/{projectsYear}/{ssProjectTitle}";
link.Description = ssProjectTitle;
- oItem["ID_x0020_Progetto"] = link;
- oItem["Cliente"] = "PAL";
- oItem["Causale"] = "02 VENDITA RICAMBI";
+ oItem["PAL_ID_Project"] = link;
+ oItem["PAL_Customer"] = "PAL";
+ oItem["PAL_DlvReason"] = "02 VENDITA RICAMBI";
oItem.Update();
ctx.ExecuteQuery();
@@ -542,24 +525,27 @@ namespace SharePointOnlineUtils
{
var listTitle = $"SottoCommesse {ssProjectTitle}";
#region Field
- Console.WriteLine($"> Inizializzata la fase di creazione dei campi in 'SottoCommesse {ssProjectTitle}'.");
+ Console.WriteLine($"> Inizializzata la fase di importazione dei campi in 'SottoCommesse {ssProjectTitle}'.");
Web web = ctx.Web;
List list = web.Lists.GetByTitle(listTitle);
- List projectsList = web.Lists.GetByTitle(listTitle);
-
+ var siteField = ctx.Site.RootWeb ;
ctx.Load(list, l => l.Fields);
- ctx.Load(projectsList, b => b.Id);
- ctx.ExecuteQuery();
-
- Field lookupItemField = list.Fields.AddFieldAsXml(@"", true, AddFieldOptions.DefaultValue);
- Field lookupArticleNumberField = list.Fields.AddFieldAsXml(@"", true, AddFieldOptions.DefaultValue);
- Field lookupArticleDescriptionField = list.Fields.AddFieldAsXml(@"", true, AddFieldOptions.DefaultValue);
- Field lookupMachineSerialNumberField = list.Fields.AddFieldAsXml(@"", true, AddFieldOptions.DefaultValue);
+ ctx.Load(siteField, s => s.Fields);
ctx.ExecuteQuery();
- Console.WriteLine($"> Completata la fase di creazione dei campi in 'SottoCommesse {ssProjectTitle}'.");
+ string[] fieldName = { "Item", "Codice Articolo", "Descrizione Articolo", "Matricola Macchina" };
+
+ foreach (var fn in fieldName)
+ {
+ var Fields = siteField.Fields.GetByTitle(fn);
+ list.Fields.Add(Fields);
+ }
+
+ ctx.ExecuteQuery();
+
+ Console.WriteLine($"> Completata la fase di importazione dei campi in 'SottoCommesse {ssProjectTitle}'.");
#endregion
#region View
@@ -686,10 +672,10 @@ namespace SharePointOnlineUtils
var dsItem = list.RootFolder.Folders.GetByUrl(spt).ListItemAllFields;
dsItem["_ExtendedDescription"] = "valueDescription";
- dsItem["Item"] = "valueItem";
- dsItem["Codice_x0020_Articolo"] = "valueItemCode";
- dsItem["Descrizione_x0020_Articolo"] = "valueItemDescription";
- dsItem["Matricola_x0020_Macchina"] = "valueSerialNumber";
+ dsItem["PAL_Item"] = "valueItem";
+ dsItem["PAL_ItemCode"] = "valueItemCode";
+ dsItem["PAL_ItemDescription"] = "valueItemDescription";
+ dsItem["PAL_SerialNumber"] = "valueSerialNumber";
dsItem.Update();
ctx.ExecuteQuery();
diff --git a/console_spo_utils/obj/console_spo_utils.csproj.nuget.dgspec.json b/console_spo_utils/obj/console_spo_utils.csproj.nuget.dgspec.json
index 619fd65..f725b7d 100644
--- a/console_spo_utils/obj/console_spo_utils.csproj.nuget.dgspec.json
+++ b/console_spo_utils/obj/console_spo_utils.csproj.nuget.dgspec.json
@@ -15,11 +15,13 @@
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\DevExpress 21.2\\Components\\Offline Packages",
+ "C:\\Program Files\\DevExpress 22.1\\Components\\Offline Packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\cbo\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\DevExpress 21.2.config",
+ "C:\\Program Files (x86)\\NuGet\\Config\\DevExpress 22.1.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
@@ -29,6 +31,7 @@
"sources": {
"C:\\Program Files (x86)\\DevExpress 21.2\\Components\\System\\Components\\Packages": {},
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
+ "C:\\Program Files\\DevExpress 22.1\\Components\\System\\Components\\Packages": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
diff --git a/console_spo_utils/obj/console_spo_utils.csproj.nuget.g.props b/console_spo_utils/obj/console_spo_utils.csproj.nuget.g.props
index 40541e9..ee5a3de 100644
--- a/console_spo_utils/obj/console_spo_utils.csproj.nuget.g.props
+++ b/console_spo_utils/obj/console_spo_utils.csproj.nuget.g.props
@@ -5,13 +5,14 @@
NuGet
$(MSBuildThisFileDirectory)project.assets.json
$(UserProfile)\.nuget\packages\
- C:\Users\cbo\.nuget\packages\;C:\Program Files (x86)\DevExpress 21.2\Components\Offline Packages;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages
+ C:\Users\cbo\.nuget\packages\;C:\Program Files (x86)\DevExpress 21.2\Components\Offline Packages;C:\Program Files\DevExpress 22.1\Components\Offline Packages;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages
PackageReference
6.2.1
+
\ No newline at end of file
diff --git a/console_spo_utils/obj/project.assets.json b/console_spo_utils/obj/project.assets.json
index 970651c..1ece55b 100644
--- a/console_spo_utils/obj/project.assets.json
+++ b/console_spo_utils/obj/project.assets.json
@@ -6169,6 +6169,7 @@
"packageFolders": {
"C:\\Users\\cbo\\.nuget\\packages\\": {},
"C:\\Program Files (x86)\\DevExpress 21.2\\Components\\Offline Packages": {},
+ "C:\\Program Files\\DevExpress 22.1\\Components\\Offline Packages": {},
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
},
"project": {
@@ -6182,11 +6183,13 @@
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\DevExpress 21.2\\Components\\Offline Packages",
+ "C:\\Program Files\\DevExpress 22.1\\Components\\Offline Packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\cbo\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\DevExpress 21.2.config",
+ "C:\\Program Files (x86)\\NuGet\\Config\\DevExpress 22.1.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
@@ -6196,6 +6199,7 @@
"sources": {
"C:\\Program Files (x86)\\DevExpress 21.2\\Components\\System\\Components\\Packages": {},
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
+ "C:\\Program Files\\DevExpress 22.1\\Components\\System\\Components\\Packages": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {