update directory name and access visibility
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
using console_spo_utils.Interfaces.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.SharePoint.Client;
|
||||
|
||||
namespace console_spo_utils.Services;
|
||||
|
||||
internal class QuotationDocLibraryService : IQuotationDocLibraryService
|
||||
{
|
||||
private readonly ILogger<QuotationDocLibraryService> logger;
|
||||
|
||||
public QuotationDocLibraryService(
|
||||
ILogger<QuotationDocLibraryService> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
public void Create(string libName, ClientContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region New DocLib
|
||||
|
||||
Console.WriteLine($"> Inizializzata la fase di creazione '{libName}'.");
|
||||
|
||||
Web web = ctx.Web;
|
||||
ctx.Load(web, w => w.RootFolder.WelcomePage, w => w.Url);
|
||||
|
||||
ListCreationInformation lci = new ListCreationInformation();
|
||||
lci.Title = libName;
|
||||
lci.TemplateType = (int)ListTemplateType.DocumentLibrary;
|
||||
web.Lists.Add(lci);
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
Console.WriteLine($"> Completata la fase di creazione '{libName}'.");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Field
|
||||
|
||||
Console.WriteLine($"> Inizializzata la fase di importazione dei campi '{libName}'.");
|
||||
|
||||
List list = ctx.Web.Lists.GetByTitle(libName);
|
||||
var siteField = ctx.Site.RootWeb;
|
||||
ctx.Load(list, l => l.Fields);
|
||||
ctx.Load(siteField, s => s.Fields);
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
string[] fieldName = { "ID Offerta", "Fornitore", "Causale", "Autore" };
|
||||
|
||||
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 '{libName}'.");
|
||||
|
||||
#endregion
|
||||
|
||||
#region View
|
||||
|
||||
Console.WriteLine($"> Inizializzata la fase di creazione della ListView '{libName}'.");
|
||||
|
||||
var views = list.Views;
|
||||
|
||||
ViewCreationInformation viewCreation = new ViewCreationInformation();
|
||||
|
||||
viewCreation.SetAsDefaultView = true;
|
||||
viewCreation.Title = libName;
|
||||
viewCreation.ViewTypeKind = ViewType.None;
|
||||
viewCreation.ColumnWidth = "350";
|
||||
viewCreation.ViewFields = new string[] { "Type", "Name", "ID Offerta", "Fornitore", "Causale", "Autore" };
|
||||
|
||||
var view = views.Add(viewCreation);
|
||||
|
||||
ctx.Load(view);
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
Console.WriteLine($"> Completata la fase di creazione della ListView '{viewCreation.Title}'.");
|
||||
|
||||
var customView = views.GetByTitle(viewCreation.Title);
|
||||
customView.MobileView = true;
|
||||
customView.MobileDefaultView = true;
|
||||
|
||||
customView.Update();
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
Console.WriteLine($"> Abilitata la visualizzazione su mobile '{viewCreation.Title}'.");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Shortcut on Quickmenu
|
||||
|
||||
NavigationNodeCollection spNavNodeColl = web.Navigation.QuickLaunch;
|
||||
NavigationNodeCreationInformation newNavNode = new NavigationNodeCreationInformation();
|
||||
|
||||
newNavNode.Title = $"{libName}";
|
||||
newNavNode.Url = $"{web.Url}/{libName.Replace(" ", "%20")}";
|
||||
newNavNode.AsLastNode = true;
|
||||
spNavNodeColl.Add(newNavNode);
|
||||
|
||||
ctx.ExecuteQuery();
|
||||
|
||||
Console.WriteLine($"> Il menu rapido è stato aggiornato, il collegamento a {libName} è ora disponibile.");
|
||||
|
||||
#endregion
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "QuotationDocLibraryService");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user