/// <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); } }
public static IEnumerable <TList> GetLists <TList>(this SPWeb web, SPBaseType baseType, string templateName) where TList : SPList { SPListTemplate template = GetListTemplate(web, templateName); return(web.GetLists <TList>(template.BaseType, template)); }
/// <summary> /// Task for adding a SPRole to a site. /// </summary> protected override void ExecuteTask() { try { SPSite site = new SPSite(Url); SPWeb web = site.OpenWeb(WebUrl); SPListTemplate listTemplate = GetListTemplate(web); SPDocTemplate docTemplate = GetDocTemplate(web); web.Lists.Add( Title, Description, listTemplate, docTemplate); } catch (SPException ex) { throw new BuildException( string.Format("Cannot add list: {0} to site: {1}.", Title, Url), Location, ex); } catch (System.IO.FileNotFoundException fnf) { throw new BuildException( string.Format("Cannot add list: {0} to invalid web url: {1}.", Title, WebUrl), Location, fnf); } }
public static TList AddList <TList>(this SPWeb web, string listName, string description, SPListTemplate template, Action <TList> action) where TList : SPList { var list = (TList)web.Lists.TryGetList(listName); if (list == null) { Guid listId = web.Lists.Add(listName, description, template); list = (TList)web.Lists.GetList(listId, false); } if (action != null) { try { action(list); } finally { list.Update(); } } return(list); }
/// <summary> /// Finds the list template corresponding to the specified name /// </summary> /// <param name="web">The current web</param> /// <param name="templateName">The list template name</param> /// <returns>The list template</returns> public static SPListTemplate GetListTemplate(this SPWeb web, string templateName) { SPListTemplate template = web.ListTemplates.Cast <SPListTemplate>().FirstOrDefault( lt => lt.Name.Equals(templateName, StringComparison.InvariantCultureIgnoreCase)); return(template); }
protected BaseLibraryDefinition(SPListTemplate template) : base(template) { if (template.BaseType != SPBaseType.DocumentLibrary) { throw new NotSupportedException(); } }
public ListTemplateNode(WebNode webTreeNode, SPListTemplate template) { this.Tag = template; this.SPParent = webTreeNode.Web; this.WebTreeNode = webTreeNode; this.Setup(); }
public SPListTemplateInstance Construct(SPListTemplate listTemplate) { if (listTemplate == null) { throw new ArgumentNullException("listTemplate"); } return(new SPListTemplateInstance(this.InstancePrototype, listTemplate)); }
private static SPList createListImpl(SPWeb web, string Title, string Description, SPListTemplate template) { web.RequireNotNull("web"); Title.RequireNotNullOrEmpty("Title"); Description.RequireNotNullOrEmpty("Description"); template.RequireNotNull("template"); Guid listGuid = web.Lists.Add(Title, Description, template); return web.Lists[listGuid]; }
public static TList AddList <TList>(this SPWeb web, string internalListName, string displayListName, string description, SPListTemplate template, Action <TList> action, bool onQuickLaunch = false) where TList : SPList { TList list; internalListName = SPHelper.RemoveIllegalUrlCharacters(internalListName); SPList existingList = web.Lists.TryGetList(displayListName); if (existingList != null) { if (existingList.RootFolder.Name != internalListName) { throw new SPException(string.Format("List with Title=\"{0}\" already exists in the web [URL={1}].", displayListName, web.Url)); } if (existingList.BaseTemplate != template.Type) { throw new SPException(string.Format("Existing list with Title=\"{0}\" was not created from a template \"{2}\" in the web [URL={1}].", displayListName, web.Url, (int)template.Type)); } list = (TList)existingList; } else { list = web.Lists.GetListsByInternalName <TList>(internalListName, template).SingleOrDefault(); } if (list == null) { Guid listId = web.Lists.Add(internalListName, description, template); list = (TList)web.Lists.GetList(listId, false); } try { list.Title = displayListName; list.OnQuickLaunch = onQuickLaunch; if (action != null) { action(list); } } finally { list.Update(); } return(list); }
public SPList CreateList(SPWeb web, string Title, string Description, SPListTemplate template) { web.RequireNotNull("web"); Title.RequireNotNullOrEmpty("Title"); Description.RequireNotNullOrEmpty("Description"); template.RequireNotNull("template"); SPList list = web.Lists.TryGetList(Title); return null != list ? list : createListImpl(web, Title, Description, template) ; }
/// <summary> /// Write the directory tree of document library to a file of XML /// </summary> /// <param name="siteUrl">the url of site</param> /// <param name="libraryName">the name of document library</param> public void WriteXml(string siteUrl, string libraryName) { using (SPSite mysite = new SPSite(siteUrl)) { using (SPWeb myWeb = mysite.RootWeb) { //SPList myList = myWeb.Lists["Documents"]; SPFolder myFolder = myWeb.GetFolder(libraryName); //myFolder = myList.RootFolder; if (!myFolder.Exists) { SPListTemplate myListTemplate = myWeb.ListTemplates["Document Library"]; //SPDocTemplate myDocTemplate = (from SPDocTemplate dt in myWeb.DocTemplates where dt.Type == 122 select dt).FirstOrDefault(); //Guid myGuid = myWeb.Lists.Add(libraryName, String.Format("create document library named {0} successfully", libraryName), myListTemplate,myDocTemplate); Guid myGuid = myWeb.Lists.Add(libraryName, String.Format("create document library named {0} successfully", libraryName), myListTemplate); SPDocumentLibrary myLibrary = myWeb.Lists[myGuid] as SPDocumentLibrary; myLibrary.OnQuickLaunch = true; myLibrary.Update(); myFolder = myWeb.GetFolder(libraryName); Console.WriteLine("success"); } string changeStr = ChangeString(libraryName); XmlDocument myXmlDoc = new XmlDocument(); XmlDeclaration myXmlDeclaration = myXmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); myXmlDoc.AppendChild(myXmlDeclaration); XmlElement addWeb = myXmlDoc.CreateElement("Web"); XmlElement addLibrary = myXmlDoc.CreateElement("Library"); XmlElement myXmlNode = myXmlDoc.CreateElement(changeStr); SPList list = myFolder.DocumentLibrary; foreach (SPField item in list.Fields) { if (!item.ReadOnlyField) { myXmlNode.SetAttribute(ChangeString(item.Title), item.Type.ToString()); } } addLibrary.AppendChild(GetSubNodeAllDirectory(myXmlNode, myFolder, myXmlDoc)); addWeb.AppendChild(addLibrary); myXmlDoc.AppendChild(addWeb); string sFilePath = "C:\\Users\\administrator.SPCARTOON\\Desktop\\XML"; string sFileName = "MySharePointXML2"; sFileName = sFilePath + @"\\" + sFileName; //文件的绝对路径 using (XmlTextWriter xmlTextWriter = new XmlTextWriter(@sFileName, Encoding.UTF8) { Formatting = Formatting.Indented, IndentChar = '\t', Indentation = 1 }) { myXmlDoc.Save(xmlTextWriter); Console.WriteLine("sss"); } } } }
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); } }
/// <summary> /// Gets a <see cref="SPListTemplate"/> by <see cref="ListTemplateName"/> /// </summary> /// <param name="web"></param> /// <returns></returns> private SPListTemplate GetListTemplate(SPWeb web) { SPListTemplate listTemplate = null; if (web != null) { listTemplate = web.ListTemplates[ListTemplateName]; } return(listTemplate); }
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); }
/// <summary> /// This method used to create 'Disable Feature Message' list, which will hold generic message i.e. to displayed on features page /// </summary> /// <param name="web"></param> private void disableCustomMsgList(SPWeb web) { SPList list = web.Lists.TryGetList(Settings.custMessageListName); if (list == null) { SPListTemplate template = web.ListTemplates["Custom List"]; Guid listId = web.Lists.Add(Settings.custMessageListName, Settings.custMessageListName, template); list = web.GetList(web.Url.Trim() + "/Lists/" + Settings.custMessageListName); list.Fields.Add("Description", SPFieldType.Text, true); SPView view = list.Views["All Items"]; view.ViewFields.Add("Description"); view.Update(); list.Update(); } }
/// <summary> /// This method used to create 'Disable Features List' list, which will be used to hold all the features to be disabled /// </summary> /// <param name="web"></param> private void featuresList(SPWeb web) { SPList list = web.Lists.TryGetList(Settings.featureIdsListName); if (list == null) { SPListTemplate template = web.ListTemplates["Custom List"]; Guid listId = web.Lists.Add(Settings.featureIdsListName, Settings.featureIdsListName, template); list = web.GetList(web.Url.Trim() + "/Lists/" + Settings.featureIdsListName); list.Fields.Add("FeatureID", SPFieldType.Text, true); SPView view = list.Views["All Items"]; view.ViewFields.Add("FeatureID"); view.Update(); list.Update(); } }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { var web = (properties.Feature.Parent as SPSite).RootWeb; string groupName = "WOFHonorGroup"; string listName = "WallOfHonorList"; try { if (!GroupExistsInSiteCollection(web, groupName)) { web.SiteGroups.Add(groupName, web.CurrentUser, web.CurrentUser, "Группа для редактирования доски почета"); web.AssociatedGroups.Add(web.SiteGroups[groupName]); web.Update(); } SPUser allUsers = web.AllUsers[@"c:0(.s|true"]; SPRoleAssignment roleAssignmentEdit = new SPRoleAssignment(web.SiteGroups[groupName]); SPRoleAssignment roleAssignmentRead = new SPRoleAssignment((SPPrincipal)allUsers); SPRoleDefinition roleDefinitionEdit = web.RoleDefinitions.GetByType(SPRoleType.Contributor); SPRoleDefinition roleDefinitionRead = web.RoleDefinitions.GetByType(SPRoleType.Reader); roleAssignmentEdit.RoleDefinitionBindings.Add(roleDefinitionEdit); roleAssignmentRead.RoleDefinitionBindings.Add(roleDefinitionRead); if (web.Lists.TryGetList(listName) == null) { web.AllowUnsafeUpdates = true; SPListTemplate template = web.ListTemplates["WallOfHonorList"]; web.Lists.Add("Доска почета", "Доска почета", template); } SPList list = web.Lists["Доска почета"]; if (!list.HasUniqueRoleAssignments) { list.BreakRoleInheritance(false); list.RoleAssignments.Add(roleAssignmentEdit); list.RoleAssignments.Add(roleAssignmentRead); list.Update(); } } catch { //Лог } }
public void ReadXml(string siteUrl, string libraryName, string xmlPath) { using (SPSite mySite = new SPSite(siteUrl)) { using (SPWeb myWeb = mySite.RootWeb) { SPFolder myFolder = myWeb.GetFolder(libraryName); if (!myFolder.Exists) { SPListTemplate myListTemplate = myWeb.ListTemplates["Document Library"]; //SPDocTemplate myDocTemplate = (from SPDocTemplate dt in myWeb.DocTemplates where dt.Type == 122 select dt).FirstOrDefault(); //Guid myGuid = myWeb.Lists.Add(libraryName, String.Format("create document library named {0} successfully", libraryName), myListTemplate,myDocTemplate); Guid myGuid = myWeb.Lists.Add(libraryName, String.Format("create document library named {0} successfully", libraryName), myListTemplate); SPDocumentLibrary myLibrary = myWeb.Lists[myGuid] as SPDocumentLibrary; myLibrary.OnQuickLaunch = true; myLibrary.Update(); myFolder = myWeb.GetFolder(libraryName); Console.WriteLine("success"); } SPList myList = myFolder.DocumentLibrary; try { if (!IsExist(myList.Fields, "Source Path")) { string str1 = myList.Fields.Add("Source Path", SPFieldType.Text, false); //myList.Fields[str1].Description = "Oliver Content Type" + DateTime.Now.ToString(); myList.Update(); //myList = subFile.DocumentLibrary; Console.WriteLine("Source Path not exist,but create"); } } catch (Exception e) { WriteLog(e.Message); } XmlDocument myXmlDoc = new XmlDocument(); myXmlDoc.Load(xmlPath); string changeStr = "Web/Library/" + ChangeString(libraryName); XmlNode myXmlNode = myXmlDoc.SelectSingleNode(changeStr); AddFileToClient(myFolder, myXmlNode); } } }
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 void btnFormLibraryNew_Click(object sender, EventArgs e) { if (tbxUserName.Text.Trim() == "" || tbxPassword.Text.Trim() == "" || tbxDomain.Text.Trim() == "") { MessageBox.Show("You should provide the Credentials before creating SharePoint Library", "Create SharePoint Library"); return; } if (drpdnlFormLibrary.Text.Trim() != "") { drpdnlFormLibrary.Text = ""; } ArrayList docLibValues = new ArrayList(); SPSite site = null; try { drpdnlFormLibrary.SelectedText = ""; docLibValues = NewDocLibrary.GetDocListValues(); WindowsImpersonationContext wic = Utility.CreateIdentity(tbxUserName.Text.Trim(), tbxDomain.Text.Trim(), tbxPassword.Text.Trim()).Impersonate(); //check whether user has entered full url including "http" if (tbxSharePointURL.Text.StartsWith("http")) { site = new SPSite(tbxSharePointURL.Text.Trim()); } else { site = new SPSite("http://" + tbxSharePointURL.Text.Trim()); } SPWeb web = site.OpenWeb(); SPListTemplate docLibrary = web.ListTemplates["Document Library"]; drpdnlFormLibrary.Items.Add(docLibValues[0].ToString()); drpdnlFormLibrary.SelectedText = docLibValues[0].ToString(); tbxDocLibDesc.Text = docLibValues[1].ToString(); web.Lists.Add(drpdnlFormLibrary.Text.Trim(), docLibValues[1].ToString(), docLibrary); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "Error"); } }
// Private Methods (2) /// <summary> /// Creates the file store. /// </summary> /// <returns></returns> private SPDocumentLibrary CreateFileStore() { _spWeb.AllowUnsafeUpdates = true; SPListTemplate spListTemplate = _spWeb.ListTemplates["Document Library"]; SPDocTemplate spDocTemplate = (from SPDocTemplate dt in _spWeb.DocTemplates where dt.Type == 100 select dt).FirstOrDefault(); Guid fileStoreId = _spWeb.Lists.Add(FILE_STORE_NAME, "EPM Live File Store", spListTemplate, spDocTemplate); var spDocumentLibrary = (SPDocumentLibrary)_spWeb.Lists[fileStoreId]; spDocumentLibrary.OnQuickLaunch = false; spDocumentLibrary.Hidden = true; spDocumentLibrary.Update(); _spWeb.AllowUnsafeUpdates = false; return((SPDocumentLibrary)_spWeb.Lists[FILE_STORE_NAME]); }
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(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); }
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 static IEnumerable <TList> GetLists <TList>(this SPWeb web, SPBaseType baseType, SPListTemplate template) where TList : SPList { if (template == null) { throw new ArgumentNullException("template"); } return(web.GetLists <TList>(template.BaseType, template.Type)); }
public TemplateHolderForList(SPListTemplate template) { this.Template = template; }
private void bulkSiteCreation(bool onlyValidate) { //--Validate if (NewSiteOrList.ListOfNewLists == null || NewSiteOrList.ListOfNewLists.Count == 0) { AddToRtbLocal("The list of SharePoint Lists to create is empty.\r\n", StyleType.bodyRed); return; } if (cboListTemplates.SelectedItem == null) { AddToRtbLocal("Please select a List Template.\r\n", StyleType.bodyRed); return; } for (int i = 0; i < NewSiteOrList.ListOfNewLists.Count - 1; i++) { if (NewSiteOrList.ListOfNewLists[i].UrlName == NewSiteOrList.ListOfNewLists[i + 1].UrlName) { AddToRtbLocal("The List URL " + NewSiteOrList.ListOfNewLists[i].UrlName + " is listed twice.\r\n", StyleType.bodyRed); return; } } int counterCreated = 0; int counterListToCreate = 0; try { FrmCancelRunning.ToggleEnabled(true); SPWeb parentWeb = Util.RetrieveWeb(txtTargetSite.Text, rtbSiteValidateMessage); if (parentWeb == null) { return; } txtTargetSite.Text = parentWeb.Url; //-- SPListTemplate targetTemplate = ((TemplateHolderForList)cboListTemplates.SelectedItem).Template; AddToRtbLocal("Creating new Lists beneath parent site ", StyleType.bodySeaGreen); AddToRtbLocal(parentWeb.Url + "\r\n", StyleType.bodyBlue); AddToRtbLocal("Using list template: ", StyleType.bodySeaGreen); AddToRtbLocal(targetTemplate.Name + "\r\n", StyleType.bodyBlue); AddToRtbLocal("\r\n", StyleType.bodyBlack); Application.DoEvents(); //-- List <NewSiteOrList> currentListUrlNamesAndTitles = new List <NewSiteOrList>(); foreach (SPList list in parentWeb.Lists) { currentListUrlNamesAndTitles.Add(new NewSiteOrList(list.RootFolder.Name.ToUpper(), list.Title.ToUpper())); } foreach (NewSiteOrList ns in NewSiteOrList.ListOfNewLists) { if (GlobalVars.CancelRunning) { throw new Eh.CancelException(); } counterListToCreate++; AddToRtbLocal("#" + (counterListToCreate) + ") ", StyleType.bodyBlackBold); if (listAlreadyExists(currentListUrlNamesAndTitles, ns)) { AddToRtbLocal("List " + ns.UrlName + " already exists\r\n", StyleType.bodyBlue); } else { if (onlyValidate) { AddToRtbLocal("List to be created: ", StyleType.bodyBlack); AddToRtbLocal(ns.ToString() + "\r\n", StyleType.bodyBlue); } else { AddToRtbLocal("Creating list:" + ns.ToString(), StyleType.bodyBlack); Guid newListGuid = parentWeb.Lists.Add(ns.UrlName, "", targetTemplate); counterCreated++; SPList newList = parentWeb.Lists[newListGuid]; newList.Title = ns.Title; newList.Update(); AddToRtbLocal(" success\r\n", StyleType.bodySeaGreen); //-- if (chkAddListToQuickLanuch.Checked) { newList.OnQuickLaunch = true; newList.Update(); AddToRtbLocal(" Quicklanuch node added for list\r\n", StyleType.bodyBlack); } } } SmartStepUtil.ScrollToBottom(rtbDisplay); Application.DoEvents(); } } catch (Eh.CancelException) { AddToRtbLocal("Cancelled by user\r\n", StyleType.bodyRed); } catch (Exception ex) { AddToRtbLocal("Error: " + ex.Message + "\r\n", StyleType.bodyRed); } finally { FrmCancelRunning.ToggleEnabled(false); AddToRtbLocal("\r\n\r\n", StyleType.bodyBlack); if (!onlyValidate) { AddToRtbLocal("DONE. Count of new lists created: " + counterCreated, StyleType.bodyDarkGray); } } }
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)); }
private static Guid CreateList(SPWeb web, string title, string description, SPListTemplate template) { try { return web.Lists.Add(title, description, template); } catch(Exception ex) { throw ex; } }
public SPList EnsureList(SPWeb web, string name, string description, SPListTemplate template) { var list = this.TryGetList(web, name); if (list != null) { // List already exists, check for correct template if (list.BaseTemplate != template.Type) { throw new SPException(string.Format(CultureInfo.InvariantCulture, "List {0} has list template type {1} but should have list template type {2}.", name, list.BaseTemplate, template.Type)); } } else { // Create new list var id = web.Lists.Add(name, description, template); list = web.Lists[id]; } return list; }
protected BaseListDefinition(SPListTemplate template) : base() { _template = template; }
public static IEnumerable <TList> GetListsByInternalName <TList>(this SPListCollection lists, string internalName, SPListTemplate template) where TList : SPList { return(lists.GetListsByInternalName <TList>(internalName, template.BaseType, template.Type)); }
public SPListTemplateInstance(ObjectInstance prototype, SPListTemplate listTemplate) : this(prototype) { this.m_listTemplate = listTemplate; }