Ora Funziona
Controlla se la pagina "Commesse YYYY" esiste e se non è presente la crea.
This commit is contained in:
@@ -52,7 +52,8 @@ namespace SharePointOnlineUtils
|
||||
|
||||
public static async Task ProjectsByYearSite(string siteCollection, string user, SecureString psw)
|
||||
{
|
||||
string projectsYear = "Commesse" + DateTime.Now.Year.ToString();
|
||||
string year = DateTime.Now.Year.ToString();
|
||||
string projectsYear = "Commesse" + year;
|
||||
Uri site = new Uri(siteCollection + "/sites/" + projectsYear);
|
||||
|
||||
using (var authenticationManager = new AuthenticationManager())
|
||||
@@ -65,7 +66,7 @@ namespace SharePointOnlineUtils
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{projectsYear} - Non esiste, a breve verrà generata.");
|
||||
SPCheck.ProjectsYearGenerator(site, projectsYear, siteCollection, user, psw);
|
||||
SPCheck.ProjectsYearGenerator(year, site, user, psw);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,36 +89,11 @@ namespace SharePointOnlineUtils
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task ProjectsYearGenerator(Uri site, string projectsYear, string sitePath, string user, SecureString psw)
|
||||
public static async Task ProjectsYearGenerator(string year, Uri site, string user, SecureString psw)
|
||||
{
|
||||
#region old
|
||||
//Uri site = new Uri(siteCollection);
|
||||
//using (var authenticationManager = new AuthenticationManager())
|
||||
//using (var ctx = authenticationManager.GetContext(site, user, psw))
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// WebCreationInformation creation = new WebCreationInformation()
|
||||
// {
|
||||
// Title = projectsYear,
|
||||
// Url = projectsYear
|
||||
// };
|
||||
//
|
||||
// Web newWeb = ctx.;
|
||||
//
|
||||
// ctx.Load(newWeb, w => w.Title);
|
||||
// ctx.ExecuteQuery();
|
||||
//
|
||||
// Console.WriteLine($"Il sito è stato creato con successo.\n{site}/sites/{projectsYear}");
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine($"Non è stato possibile creare la pagina: {ex.Message}");
|
||||
// }
|
||||
//
|
||||
//}
|
||||
#endregion
|
||||
Uri path = new Uri(sitePath);
|
||||
string siteAdmin = "https://italsortbuttrio-admin.sharepoint.com";
|
||||
|
||||
Uri path = new Uri(siteAdmin);
|
||||
|
||||
using (var authenticationManager = new AuthenticationManager())
|
||||
using (var ctx = authenticationManager.GetContext(path, user, psw))
|
||||
@@ -128,8 +104,9 @@ namespace SharePointOnlineUtils
|
||||
var scp = new SiteCreationProperties();
|
||||
|
||||
scp.Url = site.ToString();
|
||||
scp.Title = projectsYear;
|
||||
scp.Title = "Commesse " + year;
|
||||
scp.Owner = user;
|
||||
scp.Template = "SITEPAGEPUBLISHING#0";
|
||||
|
||||
SpoOperation spo = tenant.CreateSite(scp);
|
||||
ctx.Load(tenant);
|
||||
@@ -138,7 +115,7 @@ namespace SharePointOnlineUtils
|
||||
|
||||
while (!spo.IsComplete)
|
||||
{
|
||||
//Wait for 30 seconds and then try again
|
||||
Console.WriteLine($"Il sito '../{scp.Title}' è in fase di creazione.");
|
||||
System.Threading.Thread.Sleep(30000);
|
||||
spo.RefreshLoad();
|
||||
ctx.ExecuteQuery();
|
||||
@@ -148,7 +125,7 @@ namespace SharePointOnlineUtils
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Xe da qualcosa storto. " + ex.Message);
|
||||
Console.WriteLine("Qualcosa è andato storto. (" + ex.Message + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user