private void DownloadAndInstallList(string listname, string template, string displayname) { LogMessage(listname); try { LogMessage("\tDownloading"); using (WebClient webClient = new WebClient()) { webClient.Headers.Add(FBAHeader, FBAValue); ServicePointManager.ServerCertificateValidationCallback += delegate( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); }; webClient.Credentials = CoreFunctions.GetStoreCreds(); byte[] fileBytes = null; fileBytes = webClient.DownloadData(storeurl + "/43Upgrade/" + template + ".stp"); SPFile f = solutions.RootFolder.Files.Add("43" + template + ".stp", fileBytes, true); SPListItem li = f.GetListItem(); li["Title"] = "43" + template; li.Update(); } if (SPWeb.Lists.TryGetList(displayname) == null) { LogMessage("\tCreating"); SPListTemplateCollection lc = SPSite.GetCustomListTemplates(SPWeb); SPListTemplate temp = lc["43" + template]; Guid list = SPWeb.Lists.Add(listname, "", temp); SPList oList = SPWeb.Lists[list]; oList.Title = displayname; oList.Hidden = true; oList.Update(); } else { LogMessage("\tNot Creating ", listname + ": List exists", 2); } } catch (Exception ex) { LogMessage("", ex.Message, 3); } }
private SPList CreateList(SPSite site, SPWeb web) { SPList list = null; try { list = web.Lists["Presently Documents"]; } catch { list = null; } try { if ((list == null)) { web.AllowUnsafeUpdates = true; SPListTemplateCollection customListTemplates = site.GetCustomListTemplates(web); //create the connection library using the uploaded list template SPListTemplate listTemplate = customListTemplates["Presently Document Template"]; Guid guid = web.Lists.Add("Presently Documents", "A custom list to store presently documents", listTemplate); SPList presentlyList = web.Lists.GetList(guid, false); presentlyList.OnQuickLaunch = true; presentlyList.Update(); web.AllowUnsafeUpdates = false; return(presentlyList); } return(list); } catch (Exception err) { StringBuilder sb = new StringBuilder(); sb.Append("<div>" + err.Message + "</div>" + "<div>" + err.StackTrace + "</div>"); Literal error = new Literal(); error.Text = sb.ToString(); this.Controls.Add(error); return(null); } }
private SPList CreateList(SPSite site, SPWeb web) { SPList list = null; try { list = web.Lists["Presently Documents"]; } catch { list = null; } try { if ((list == null)) { web.AllowUnsafeUpdates = true; SPListTemplateCollection customListTemplates = site.GetCustomListTemplates(web); //create the connection library using the uploaded list template SPListTemplate listTemplate = customListTemplates["Presently Document Template"]; Guid guid = web.Lists.Add("Presently Documents", "A custom list to store presently documents", listTemplate); SPList presentlyList = web.Lists.GetList(guid, false); presentlyList.OnQuickLaunch = true; presentlyList.Update(); web.AllowUnsafeUpdates = false; return presentlyList; } return list; } catch (Exception err) { StringBuilder sb = new StringBuilder(); sb.Append("<div>" + err.Message + "</div>" + "<div>" + err.StackTrace + "</div>"); Literal error = new Literal(); error.Text = sb.ToString(); this.Controls.Add(error); return null; } }
public override bool Perform() { try { SPSecurity.RunWithElevatedPrivileges(() => { using (var spSite = new SPSite(Web.Site.ID)) { using (SPWeb spWeb = spSite.OpenWeb()) { LogTitle(GetWebInfo(spWeb), 1); SPList spList = spWeb.Lists.TryGetList(LIST_NAME); if (spList == null) { LogMessage("Downloading new " + LIST_NAME + " list", 2); var catalog = (SPDocumentLibrary)Web.Site.GetCatalog(SPListTemplateType.ListTemplateCatalog); const string TEMPLATE_NAME = LIST_NAME + " [5.5]"; using (var webClient = new WebClient()) { byte[] bytes = webClient.DownloadData(_storeUrl + "/Upgrade/" + LIST_NAME.ToLower() + ".stp"); SPFile file = catalog.RootFolder.Files.Add(LIST_NAME + "_55.stp", bytes, true); SPListItem li = file.GetListItem(); li["Title"] = TEMPLATE_NAME; li.SystemUpdate(); } LogMessage("Creating the " + LIST_NAME + " list", 2); SPListTemplateCollection listTemplates = spSite.GetCustomListTemplates(spWeb); SPListTemplate template = listTemplates[TEMPLATE_NAME]; spWeb.Lists.Add(LIST_NAME, string.Empty, template); SPList list = spWeb.Lists[LIST_NAME]; list.Title = LIST_NAME; list.Hidden = true; list.Update(); LogMessage("Adding reporting groups", 2); SPGroup owner = spWeb.SiteGroups["Administrators"]; SPUser user = spWeb.CurrentUser; AddGroup(spWeb, owner, user, "Report Viewers"); AddGroup(spWeb, owner, user, "Report Writers"); LogMessage("Processing reports", 2); string error; Reporting.ProcessIzendaReportsFromList(list, out error); if (!string.IsNullOrEmpty(error)) { LogMessage(error, MessageKind.FAILURE, 3); } else { LogMessage(null, MessageKind.SUCCESS, 3); } LogMessage("Updating Navigation link", 2); string relativeUrl = spWeb.ServerRelativeUrl.ToLower(); string newUrl = relativeUrl + "/_layouts/15/epmlive/reporting/landing.aspx"; SPList lst = spWeb.Lists.TryGetList("Installed Applications"); if (lst != null) { var qry = new SPQuery { Query = @"<Where><IsNotNull><FieldRef Name='QuickLaunch' /></IsNotNull></Where>", ViewFields = @"<FieldRef Name='QuickLaunch' />" }; SPListItemCollection listItems = lst.GetItems(qry); foreach (SPListItem item in listItems) { foreach (SPNavigationNode navNode in from node in item["QuickLaunch"].ToString().Split(',') select Convert.ToInt32(node.Split(':')[0]) into i select spWeb.Navigation.GetNodeById(i) into navNode where navNode != null let url = navNode.Url.ToLower() where url.EndsWith(relativeUrl + "/reports.aspx") || url.EndsWith(relativeUrl + "/sitepages/report.aspx") select navNode) { string message; MessageKind messageKind; UpgradeUtilities.UpdateNodeLink(newUrl, item.ID, navNode, spWeb, out message, out messageKind); LogMessage(message, messageKind, 3); } } } else { LogMessage("The list Installed Applications does not exists.", MessageKind.FAILURE, 3); } CacheStore.Current.RemoveSafely(spWeb.Url, new CacheStoreCategory(spWeb).Navigation); } else { LogMessage("Advance reporting is already configured.", MessageKind.SKIPPED, 2); } } } }); } catch (Exception e) { LogMessage(e.Message, MessageKind.FAILURE, 2); } return(true); }
public override bool Perform() { try { SPSecurity.RunWithElevatedPrivileges(() => { using (var spSite = new SPSite(Web.Site.ID)) { using (SPWeb spWeb = spSite.OpenWeb(Web.ID)) { if (!spWeb.IsRootWeb) { LogMessage(spWeb.Title + " is not a root web.", MessageKind.SKIPPED, 2); return; } LogMessage("Downloading new " + SETTINGS_LIST + " list", 2); var catalog = (SPDocumentLibrary)Web.Site.GetCatalog(SPListTemplateType.ListTemplateCatalog); const string TEMPLATE_NAME = SETTINGS_LIST + " [5.5]"; using (var webClient = new WebClient()) { byte[] bytes = webClient.DownloadData(_storeUrl + "/Upgrade/" + SETTINGS_LIST.ToLower() + ".stp"); SPFile file = catalog.RootFolder.Files.Add(SETTINGS_LIST.Replace(" ", "_") + "_55.stp", bytes, true); SPListItem li = file.GetListItem(); li["Title"] = TEMPLATE_NAME; li.SystemUpdate(); } SPList list = Web.Lists.TryGetList(SETTINGS_LIST); if (list != null) { LogMessage("Deleting old " + SETTINGS_LIST + " list", 2); if (!list.AllowDeletion) { list.AllowDeletion = true; list.Update(); } list.Delete(); LogMessage(null, MessageKind.SUCCESS, 4); } LogMessage("Creating the " + SETTINGS_LIST + " list", 2); SPListTemplateCollection listTemplates = spSite.GetCustomListTemplates(spWeb); SPListTemplate template = listTemplates[TEMPLATE_NAME]; spWeb.Lists.Add(SETTINGS_LIST, string.Empty, template); SPList spList = spWeb.Lists[SETTINGS_LIST]; spList.Title = SETTINGS_LIST; spList.Hidden = true; spList.AllowDeletion = false; spList.Update(); LogMessage(null, MessageKind.SUCCESS, 4); SPList appList = spWeb.Lists["Installed Applications"]; SPListItemCollection apps = appList.Items; var tsAppExists = apps.Cast <SPListItem>().Any(app => app.Title.Equals("Timesheets")); if (tsAppExists) { return; } LogMessage("The Timesheets app is not installed", 2); LogMessage("Removing the Timesheets link from the navigation", 3); SPList settingsList = spWeb.Lists[SETTINGS_LIST]; SPListItem tsItem = settingsList.GetItemById(90); tsItem.Delete(); settingsList.Update(); LogMessage(null, MessageKind.SUCCESS, 4); } } }); } catch (Exception e) { LogMessage(e.Message, MessageKind.FAILURE, 2); } finally { try { CacheStore.Current.RemoveSafely(Web.Url, new CacheStoreCategory(Web).Navigation); } catch { } } return(true); }