/// <summary> /// Applies the list type changes. /// </summary> /// <param name="web">The web.</param> /// <param name="cqwp">The content query web part.</param> /// <param name="listType">Type of the list.</param> private static void ApplyListTypeChanges(SPWeb web, ContentByQueryWebPart cqwp, string listType) { if (listType == null) { return; } using (SPWeb rootWeb = web.Site.RootWeb) { SPListTemplateCollection listTemplates = rootWeb.ListTemplates; SPListTemplate template = listTemplates[listType]; if (template == null) { throw new SPException("List template (type) not found."); } cqwp.BaseType = string.Empty; cqwp.ServerTemplate = Convert.ToString((int)template.Type, CultureInfo.InvariantCulture); bool isGenericList = template.BaseType == SPBaseType.GenericList; bool isIssueList = template.BaseType == SPBaseType.Issue; bool isLinkList = template.Type == SPListTemplateType.Links; cqwp.UseCopyUtil = !isGenericList ? isIssueList : (isLinkList ? false : true); } }
private void lnkShowAllTemplates_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { SPWeb web = Util.RetrieveWeb(txtTargetSite.Text, rtbSiteValidateMessage); if (web == null) { return; } txtTargetSite.Text = web.Url; SPListTemplateCollection templates = web.Site.GetCustomListTemplates(web); rtbDisplay.Clear(); AddToRtbLocal("Custom List Templates", StyleType.titleChocolate); AddToRtbLocal(" for site collection ", StyleType.bodyBlack); AddToRtbLocal(web.Site.RootWeb.Url + "\r\n", StyleType.bodyBlue); foreach (SPListTemplate template in templates) { AddToRtbLocal("List Template Name:" + template.Name + ", InteralName:" + template.InternalName + "\r\n", StyleType.bodyBlack); } if (templates.Count == 0) { AddToRtbLocal("(No Custom List Templates found)\r\n", StyleType.bodyBlack); } }
public SPListTemplateCollectionInstance(ObjectInstance prototype, SPListTemplateCollection listTemplateCollection) : this(prototype) { if (listTemplateCollection == null) { throw new ArgumentNullException("listTemplateCollection"); } m_listTemplateCollection = listTemplateCollection; }
private static void ShowListTemplates(SPWeb Web) { SPListTemplateCollection templates = Web.ListTemplates; foreach (SPListTemplate l in templates) { Console.WriteLine(string.Format("List: {0}, Categorie: {1}, Custom: {2}", l.Name, l.CategoryType, l.IsCustomTemplate)); } }
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 static SPDocumentLibrary getDocumentLibrary(SPWeb web, string listName) { SPDocumentLibrary library = web.Lists.TryGetList(listName) as SPDocumentLibrary; if (library == null) { SPListTemplateCollection listTemplates = web.Site.GetCustomListTemplates(web); SPListTemplate listTemplate = listTemplates["SECPKM_Library"]; Guid libraryUid = web.Lists.Add(listName, listName, listTemplate); library = web.Lists[libraryUid] as SPDocumentLibrary; } return(library); }
public SPListTemplate GetListTemplate(SPListTemplateCollection listTemplates, string templateName) { listTemplates.RequireNotNull("listTemplates"); templateName.RequireNotNullOrEmpty("templateName"); try { return listTemplates[templateName]; } catch (Exception exception) { LogUtility logUtility = new LogUtility(); logUtility.TraceDebugException("Can't find list template", GetType(), exception); return null; } }
public static void CreateList(SPWeb web) { //SPSite site = SPContext.Current.Site; //site.AllowUnsafeUpdates = true; //SPWeb web = site.RootWeb; web.AllowUnsafeUpdates = true; SPListCollection coll = web.Lists; SPListTemplateCollection temlcoll = web.ListTemplates; SPDocTemplateCollection docTemp = web.DocTemplates; SPFieldCollection fieldcoll = web.Fields; SPListTemplate temp = temlcoll[0]; //SPListTemplateType.CustomGrid is a list template that works like table in ASP.NET or Excel sheet. Guid gd = coll.Add(Constants.listName, "A custom list to store Record data", SPListTemplateType.CustomGrid); coll[gd].Fields.Add(Constants.fieldUrl, SPFieldType.Note, true); coll[gd].Fields.Add(Constants.fieldDate, SPFieldType.Text, true); coll[gd].Fields.Add(Constants.fieldUser, SPFieldType.Text, true); //update the custom list with all those newly created fields coll[gd].Update(); //create the view for display in the site - both sides must match string defaultquery = coll[gd].Views[0].Query; SPViewCollection viewcoll = coll[gd].Views; Guid anothergd = coll[gd].Views[0].ID; viewcoll.Delete(anothergd); System.Collections.Specialized.StringCollection viewfields = new System.Collections.Specialized.StringCollection(); //Title field is always needed by SharePoint sites and it is always automatically created by WSS/MOSS even though you didn't tell it to viewfields.Add(Constants.fieldUrl); viewfields.Add(Constants.fieldDate); viewfields.Add(Constants.fieldUser); coll[gd].Views.Add("View name", viewfields, defaultquery, 100, true, true); coll[gd].Update(); }
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 static SPListInstance CreateList(ScriptEngine engine, SPListCollection collection, SPListTemplateCollection templates, object listCreationInfo) { Guid createdListId; if (listCreationInfo == null || listCreationInfo == Null.Value || listCreationInfo == Undefined.Value) { throw new JavaScriptException(engine, "Error", "A List Creation Info object must be specified."); } var listCreationInstance = listCreationInfo as ObjectInstance; var creationInfo = JurassicHelper.Coerce <SPListCreationInformation>(engine, listCreationInfo); SPListTemplate.QuickLaunchOptions quickLaunchOptions = (SPListTemplate.QuickLaunchOptions)Enum.Parse(typeof(SPListTemplate.QuickLaunchOptions), creationInfo.QuickLaunchOption); //If dataSourceProperties property has a value, create the list instance as a BCS list. if (listCreationInstance != null && listCreationInstance.HasProperty("dataSourceProperties")) { var dataSourceInstance = listCreationInstance.GetPropertyValue("dataSourceProperties") as ObjectInstance; if (dataSourceInstance == null) { return(null); } var dataSource = new SPListDataSource(); foreach (var property in dataSourceInstance.Properties) { dataSource.SetProperty(property.Name, property.Value.ToString()); } createdListId = collection.Add(creationInfo.Title, creationInfo.Description, creationInfo.Url, dataSource); } //If listTemplate property has a value, create the list instance using the strongly-typed SPListTemplate, optionally using the docTemplate value. else if (listCreationInstance != null && listCreationInstance.HasProperty("listTemplate") && templates != null) { var listTemplateValue = listCreationInstance.GetPropertyValue("listTemplate"); SPListTemplate listTemplate = null; if (listTemplateValue is int) { listTemplate = templates.OfType <SPListTemplate>().FirstOrDefault(dt => (int)dt.Type == (int)listTemplateValue); } else { var s = listTemplateValue as string; if (s != null) { listTemplate = templates.OfType <SPListTemplate>().FirstOrDefault(dt => dt.Type.ToString() == s); } else if (listTemplateValue is ObjectInstance) { listTemplate = JurassicHelper.Coerce <SPListTemplateInstance>(engine, listTemplateValue).ListTemplate; } } if (listTemplate == null) { return(null); } if (listCreationInstance.HasProperty("docTemplate")) { var docTemplate = JurassicHelper.Coerce <SPDocTemplateInstance>(engine, listCreationInstance.GetPropertyValue("docTemplate")); createdListId = collection.Add(creationInfo.Title, creationInfo.Description, creationInfo.Url, listTemplate.FeatureId.ToString(), listTemplate.Type_Client, docTemplate.DocTemplate.Type.ToString(CultureInfo.InvariantCulture), quickLaunchOptions); } else { createdListId = collection.Add(creationInfo.Title, creationInfo.Description, creationInfo.Url, listTemplate.FeatureId.ToString(), listTemplate.Type_Client, String.Empty, quickLaunchOptions); } } //Otherwise attempt to create the list using all properties set on the creation info object. else { SPFeatureDefinition listInstanceFeatureDefinition = null; if (listCreationInstance != null && listCreationInstance.HasProperty("listInstanceFeatureDefinition")) { var featureDefinitionInstance = JurassicHelper.Coerce <SPFeatureDefinitionInstance>(engine, listCreationInstance.GetPropertyValue("listInstanceFeatureDefinition")); listInstanceFeatureDefinition = featureDefinitionInstance.FeatureDefinition; } createdListId = collection.Add(creationInfo.Title, creationInfo.Description, creationInfo.Url, creationInfo.TemplateFeatureId, creationInfo.TemplateType, creationInfo.DocumentTemplateType, creationInfo.CustomSchemaXml, listInstanceFeatureDefinition, quickLaunchOptions); } var createdList = collection[createdListId]; return(new SPListInstance(engine, null, null, createdList)); }
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); }