public static void CreateList(SPWeb web) { DeleteList(web); // New List SPListTemplateType template = SPListTemplateType.GenericList; Guid listId = web.Lists.Add(Language.SMUListName, Language.SMUListDescription, template); SPList list = web.Lists[listId]; SPContentType ct = web.AvailableContentTypes[Language.SMUChatMessage]; list.Hidden = true; #if DEBUG list.Hidden = false; #endif list.ContentTypesEnabled = true; list.EnableVersioning = false; list.ContentTypes.Add(ct); // get rid of the item content type list.ContentTypes["Item"].Delete(); CreateDefaultListView(list); ApplyGroupRoleAssignments(web, list); }
public static TList AddList <TList>(this SPWeb web, string listName, string description, SPListTemplateType 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); }
protected BaseListDefinition() { Hidden = false; OnQuickLaunch = true; EnableAttachments = true; _templateType = SPListTemplateType.GenericList; }
public void CreateList(string listName, string title, string description, SPListTemplateType template, bool quickLaunch, int readSecurity, int writeSecurity, bool enableVersioning = false) { using (SPWeb oSPWeb = oSPSite.RootWeb) { //Check to see if list already exists try { SPList targetList = oSPSite.RootWeb.Lists[listName]; } catch (ArgumentException) { //The list does not exist, thus you can create it Guid listId = oSPWeb.Lists.Add(title, description, template ); SPList newList = oSPWeb.Lists[listId]; newList.OnQuickLaunch = quickLaunch; newList.EnableVersioning = enableVersioning; newList.ReadSecurity = readSecurity; // All users have Read access to all items newList.WriteSecurity = writeSecurity; // Users can modify only items that they created newList.Update(); } } }
/// <summary> /// Gets or creates a list depending of the current isolation level. /// If the isolation level is integration or none the function loads the list from the current web (the url that was specified in the constructor). /// If the isolation level is fake a list will be added to the faked web instance. /// </summary> /// <param name="name">The name of the list.</param> /// <param name="type">The type (SPListTemplateType) of the list.</param> /// <param name="fields">An optional array of strings. For each value a text field will be added to the list.</param> /// <returns>The list instance.</returns> public virtual SPList GetOrCreateList(string name, SPListTemplateType type, params string[] fields) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } if (isolationLevel == IsolationLevel.Integration || isolationLevel == SPEmulators.IsolationLevel.None) { return(web.Lists[name]); } else { var id = web.Lists.Add(name, string.Empty, type); var list = web.Lists[id]; if (fields.Length > 0) { Array.ForEach(fields, (s) => { list.Fields.Add(s, SPFieldType.Text, false); }); list.Update(); } return(list); } }
private SPList CreateList(string title, string description, SPListTemplateType listTemplateType) { var list = web.Lists.TryGetList(title); if (list == null) { var id = web.Lists.Add(title, description, listTemplateType); list = web.Lists[id]; try { foreach (var creator in creators) { creator.CreateField(list); } return(list); } catch (Exception ex) { if (id != Guid.Empty) { web.Lists[id].Delete(); } throw new ArgumentException( string.Format("Cannot create a list '{0}' because: {1}", title, ex.Message), ex); } } return(list); }
public ListDetails(string urlName, SPListTemplateType templateType, string title, string description, bool enforceUniqueValues) { UrlName = urlName; TemplateType = templateType; Title = title; Description = description; EnforceUniqueValues = enforceUniqueValues; }
internal static void CreateNewList(SPWeb web, string name, string desc, SPListTemplateType type) { if (web.Lists.TryGetList(name) == null) { web.Lists.Add(name, desc, type); web.Update(); } }
private SPList CreateList(string name, string title, string description, SPListTemplateType listTemplateType, bool onQuickLaunch) { SPList list = null; try { string url = string.Empty; if (listTemplateType == SPListTemplateType.PictureLibrary || listTemplateType == SPListTemplateType.DocumentLibrary || listTemplateType == SPListTemplateType.WebPageLibrary || listTemplateType == SPListTemplateType.XMLForm) { url = web.Url + "/" + name; } else { url = web.Url + "/Lists/" + name; } list = web.GetList(url); } catch (Exception) { } if (list == null) { var id = web.Lists.Add(name, description, listTemplateType); list = web.Lists[id]; try { list.OnQuickLaunch = onQuickLaunch; foreach (var creator in creators) { creator.CreateField(list); } list.Title = title; list.Update(); return(list); } catch (Exception ex) { if (id != Guid.Empty) { web.Lists[id].Delete(); } throw new ArgumentException( string.Format(CultureInfo.InvariantCulture, "Cannot create a list '{0}' because: {1}", title, ex.Message), ex); } } return(list); }
public static TList AddList <TList>(this SPWeb web, string internalListName, string displayListName, string description, SPListTemplateType 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) { 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)); } 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 static SPList EnsureListCreation(SPWeb web, string listName, string listTitle, string listDescription, SPListTemplateType type) { EnsureListCleanup(web, listTitle); Guid listGuid = web.Lists.Add(listName, listDescription, type); SPList createdList = web.Lists.GetList(listGuid, true); createdList.Title = listTitle; createdList.Update(); return createdList; }
/// <summary> /// Initializes a new instance of the <see cref="SPListAttribute"/> class with the specified location and list type. /// </summary> /// <param name="url"></param> /// <param name="listTemplateType"></param> public SPListAttribute(string url, SPListTemplateType listTemplateType) { this.Url = url; this.ListTemplateType = listTemplateType; this.ReadSecurity = SPListReadSecurity.All; this.WriteSecurity = SPListWriteSecurity.All; this.DraftVersionVisibility = DraftVisibilityType.Author; this.Description = String.Empty; this.Direction = "ltr"; }
public Guid Add(string title, string description, SPListTemplateType templateType) { var simList = (templateType == SPListTemplateType.DocumentLibrary) ? new SimSPDocumentLibrary() : new SimSPList(); simList.Title = title; this.Initialize(simList); base.Add(simList.Instance); return(simList.ID); }
public static bool CreateList(string listTitle, SPListTemplateType listType, SPWeb web) { SPList list = web.Lists.TryGetList(listTitle); if (list == null) { web.Lists.Add(listTitle, "", listType); return true; } return false; }
public SPList Create(string title, string description, SPListTemplateType template) { if (Exists(title)) { throw new Exception(string.Format("List with Name '{0}' already exists", title)); } var guid = Parent.ParentWeb.Lists.Add(title, description, template); return(Parent.ParentWeb.Lists[guid]); }
private SPList CreateList(string name, string title, string description, SPListTemplateType listTemplateType, bool onQuickLaunch) { SPList list = null; try { string url = string.Empty; if (listTemplateType == SPListTemplateType.PictureLibrary || listTemplateType == SPListTemplateType.DocumentLibrary || listTemplateType == SPListTemplateType.WebPageLibrary || listTemplateType == SPListTemplateType.XMLForm) url = web.Url + "/" + name; else url = web.Url + "/Lists/" + name; list = web.GetList(url); } catch (Exception) { } if (list == null) { var id = web.Lists.Add(name, description, listTemplateType); list = web.Lists[id]; try { list.OnQuickLaunch = onQuickLaunch; foreach (var creator in creators) { creator.CreateField(list); } list.Title = title; list.Update(); return list; } catch (Exception ex) { if (id != Guid.Empty) { web.Lists[id].Delete(); } throw new ArgumentException( string.Format(CultureInfo.InvariantCulture, "Cannot create a list '{0}' because: {1}", title, ex.Message), ex); } } return list; }
private Guid CreateList(string name, string description, SPListTemplateType type) { string listName = name; for (int i = 0; i <= CreateListTryCount; i++) { if (Web.Lists.TryGetList(listName) == null) { return(Web.Lists.Add(listName, description, type)); } listName = String.Concat(name, i.ToString(CultureInfo.InvariantCulture)); } throw new Exception(String.Format(CultureInfo.CurrentCulture, listCreationFailed, name)); }
public static DataTable GetData(this SPWeb web, SPQuery query, SPListTemplateType listType, bool recursive = false) { DataTable dt = web.GetSiteData(new SPSiteDataQuery() { Webs = recursive ? "<Webs Scope='Recursive' />" : "<Webs Scope='SiteCollection' />", Lists = string.Format("<Lists ServerTemplate=\"{0}\" />", (int)listType), Query = query.Query, ViewFields = query.ViewFields, RowLimit = query.RowLimit, QueryThrottleMode = query.QueryThrottleMode }); return(dt); }
private static SPList GetOASList(SPWeb web) { SPListTemplateType genericList = new SPListTemplateType(); genericList = SPListTemplateType.GenericList; //Check if the list exist SPList oaslist = web.Lists.TryGetList(OAS_LIST); if (oaslist == null) { //Create a custom list web.AllowUnsafeUpdates = true; Guid listGuid = web.Lists.Add(OAS_LIST, "", genericList); oaslist = web.Lists[listGuid]; oaslist.Hidden = true; //Add columns SPFieldCollection collFields = oaslist.Fields; string field1 = collFields.Add("FileId", SPFieldType.Text, false); SPField column1 = collFields.GetFieldByInternalName(field1); string field4 = collFields.Add("JobId", SPFieldType.Text, false); SPField column4 = collFields.GetFieldByInternalName(field4); string field2 = collFields.Add("Started", SPFieldType.DateTime, false); SPField column2 = collFields.GetFieldByInternalName(field2); string field3 = collFields.Add("Finished", SPFieldType.DateTime, false); SPField column3 = collFields.GetFieldByInternalName(field3); string field5 = collFields.Add("Type", SPFieldType.Integer, false); SPField column5 = collFields.GetFieldByInternalName(field5); SPView view = oaslist.DefaultView; SPViewFieldCollection collViewFields = view.ViewFields; collViewFields.Add(column1); collViewFields.Add(column2); collViewFields.Add(column3); collViewFields.Add(column4); collViewFields.Add(column5); view.Update(); } return(oaslist); }
public static SPList EnsureList(SPWeb targetWeb, SPListTemplateType templateType, string defaultTitle) { CommonHelper.ConfirmNotNull(targetWeb, "targetWeb"); CommonHelper.ConfirmNotNull(defaultTitle, "defaultTitle"); foreach (SPList list in targetWeb.Lists) { if (list.BaseTemplate == templateType) { return(list); } } Guid listId = targetWeb.Lists.Add(defaultTitle, String.Empty, templateType); return(targetWeb.Lists[listId]); }
public static ListDefinition GetListTestTemplate(SPListTemplateType listTemplateType, Action<ListDefinition> action) { var result = new ListDefinition { Title = string.Format("{0} test list", listTemplateType.ToString()), Url = string.Format("{0}testlist", listTemplateType.ToString()), TemplateType = (int)listTemplateType, Description = Guid.NewGuid().ToString(), ContentTypesEnabled = true }; if (action != null) action(result); return result; }
/// <summary> /// Checks if a list exists in a site using its "internal name" and creates it if it doesn't exist. /// </summary> /// <param name="site">The site to check.</param> /// <param name="listUrlName">The "internal name" of the list to check. This is the name that is used to create the URL for the list.</param> /// <param name="listTemplateType">A SPListTemplateType object specifying the type of list to create if it needs to be created.</param> /// <param name="listTitle">The display name of the list to use if it needs to be created.</param> /// <param name="listDescription">The description of the list to be used if it needs to be created.</param> /// <param name="isNewList">A boolean that is set to true, if a new list is created; otherwise, it is set to false.</param> /// <returns>A SPList object that references an existing or newly created list.</returns> public static SPList EnsureList(this SPWeb site, string listUrlName, SPListTemplateType listTemplateType, string listTitle, string listDescription, ref bool isNewList) { SPList list = site.TryGetList(site.GetServerRelativeListUrlPrefix() + listUrlName); isNewList = false; if (list == null) { isNewList = true; Guid listGuid = site.Lists.Add(listUrlName, listDescription, listTemplateType); list = site.Lists[listGuid]; list.Title = listTitle; list.Update(); } return(list); }
public ListDefinition(SPWeb web, string name) { Web = web; this.name = name; description = string.Empty; type = SPListTemplateType.GenericList; contentTypeNames = new List <string>(); singleFieldIndexes = new List <string>(); compoundFieldIndexes = new List <string[]>(); IsHidden = false; fieldDefinitions = new List <FieldDefinition <ListDefinition> >(); events = new Dictionary <SPEventReceiverType, Type>(); roleAssociations = new List <RoleAssociation <ListDefinition> >(); folderDefinitions = new List <FolderDefinition>(); }
public static SPList TryCreateList(SPWeb web, string listName, SPListTemplateType templateType, SPContentType[] contentTypes, string listDescription) { SPList list = web.Lists.TryGetList(listName); if (list == null) { Guid listId = web.Lists.Add(listName, listDescription, templateType); list = web.Lists[listId]; list.ContentTypesEnabled = true; foreach (SPContentType ct in contentTypes) { list.ContentTypes.Add(ct); } list.OnQuickLaunch = false; list.Update(); } return list; }
public static ListDefinition GetListTestTemplate(SPListTemplateType listTemplateType, Action <ListDefinition> action) { var result = new ListDefinition { Title = string.Format("{0} test list", listTemplateType.ToString()), Url = string.Format("{0}testlist", listTemplateType.ToString()), TemplateType = (int)listTemplateType, Description = Guid.NewGuid().ToString(), ContentTypesEnabled = true }; if (action != null) { action(result); } return(result); }
private static SPFolder GetOASLibrary(SPWeb web) { SPListTemplateType genericList = new SPListTemplateType(); genericList = SPListTemplateType.DocumentLibrary; SPFolder res = (SPFolder)web.GetFolder(OAS_LIBRARY); if (!res.Exists) { web.AllowUnsafeUpdates = true; Guid listGuid = web.Lists.Add(OAS_LIBRARY, "", genericList); SPDocumentLibrary oaslist = (SPDocumentLibrary)web.Lists[listGuid]; oaslist.Hidden = true; oaslist.Update(); } return((SPFolder)web.Folders[OAS_LIBRARY]); }
public IQueryList <T> Create <T>(string listName) where T : Item, new() { SPListTemplateType listType = GetListType <T>(); var id = Web.Lists.Add(listName, string.Empty, listType); var list = GetById <T>(id); try { var itemType = typeof(T); if (itemType.GetCustomAttributes(typeof(ContentTypeAttribute), false).Length > 0) { if (SPListTemplateType.GenericList == listType) { if (itemType != typeof(Item)) { list.RemoveContentType <Item>(); list.AddContentType <T>(); } } else { if (itemType != typeof(Document)) { list.RemoveContentType <Document>(); list.AddContentType <T>(); } } } else { list.EnsureFields(); } return(list); } catch { list.DeleteList(false); throw; } }
/// <summary> /// /// </summary> /// <param name="web"></param> /// <param name="name"></param> /// <param name="description"></param> /// <param name="template"></param> public static void CreateList(this SPWeb web, string name, string description, SPListTemplateType template = SPListTemplateType.GenericList, bool allowModeration = false, bool allowVersioning = false) { try { if (web.Lists.TryGetList(name) == null) { web.Lists.Add(name, description, template); } string listUrl = String.Format("Lists/{0}", name); SPList list = web.GetList(listUrl); list.EnableModeration = allowModeration; list.EnableVersioning = allowVersioning; list.Update(); web.Update(); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("CORE:HELPERS", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, String.Format("Exception happened in Helpers:CreateList. MESSAGE: {0}. EXCEPTION TRACE: {1} ", ex.Message, ex.StackTrace), ex.StackTrace); } }
private Guid CreateList(string name, string description, SPListTemplateType type) { if (string.IsNullOrEmpty(name)) return Guid.Empty; string listName = name; for (int i = 0; i <= CreateListTryCount; i++) { if (Web.Lists.TryGetList(listName) == null) { return Web.Lists.Add(listName, description, type); } listName = String.Concat(name, i.ToString(CultureInfo.InvariantCulture)); } throw new Exception(String.Format(CultureInfo.CurrentCulture, listCreationFailed, name)); }
public static ListDefinition GetListTestTemplate(SPListTemplateType listTemplateType) { return GetListTestTemplate(listTemplateType, null); }
private SPList CreateList(string name, string title, string description, SPListTemplateType listTemplateType, bool onQuickLaunch, bool disableListThrottling) { SPList list = null; try { string url = string.Empty; if (listTemplateType == SPListTemplateType.PictureLibrary || listTemplateType == SPListTemplateType.DocumentLibrary || listTemplateType == SPListTemplateType.WebPageLibrary || listTemplateType == SPListTemplateType.XMLForm) url = Utilities.GetWebUrl(web.Url) + "/" + name; else url = Utilities.GetWebUrl(web.Url) + "/Lists/" + name; list = web.GetList(url); } catch (FileNotFoundException fx) { Utilities.LogToULS(fx); } if (list == null) { var id = web.Lists.Add(name, description, listTemplateType); list = web.Lists[id]; } try { list.OnQuickLaunch = onQuickLaunch; foreach (var creator in creators) { creator.CreateField(list); } if (disableListThrottling) { list.EnableThrottling = false; } list.Title = title; list.Update(); return list; } catch (Exception ex) { Console.WriteLine(ex.ToString()); // web.Lists[list.ID].Delete(); throw new ArgumentException( string.Format(CultureInfo.InvariantCulture, "Cannot create a list '{0}' because: {1}", title, ex.Message), ex); } }
/// <summary> /// Checks if a list exists in a site using its "internal name" and creates it if it doesn't exist. /// </summary> /// <param name="site">The site to check.</param> /// <param name="listUrlName">The "internal name" of the list to check. This is the name that is used to create the URL for the list.</param> /// <param name="listTemplateType">A SPListTemplateType object specifying the type of list to create if it needs to be created.</param> /// <param name="listTitle">The display name of the list to use if it needs to be created.</param> /// <param name="listDescription">The description of the list to be used if it needs to be created.</param> /// <param name="isNewList">A boolean that is set to true, if a new list is created; otherwise, it is set to false.</param> /// <returns>A SPList object that references an existing or newly created list.</returns> public static SPList EnsureList(this SPWeb site, string listUrlName, SPListTemplateType listTemplateType, string listTitle, string listDescription, ref bool isNewList) { SPList list = site.TryGetList(site.GetServerRelativeListUrlPrefix() + listUrlName); isNewList = false; if (list == null) { isNewList = true; Guid listGuid = site.Lists.Add(listUrlName, listDescription, listTemplateType); list = site.Lists[listGuid]; list.Title = listTitle; list.Update(); } return list; }
public static SPList CreateList(SPWeb webSite, string listName, string listDescription, SPListTemplateType listTemplate) { // validation if (null == webSite) { throw new ArgumentNullException("webSite"); } if (string.IsNullOrEmpty(listName)) { throw new ArgumentException("listName is null or empty!"); } if (string.IsNullOrEmpty(listDescription)) { throw new ArgumentException("listDescription is null or empty!"); } SPList list = webSite.Lists.TryGetList(listName); if (null == list) { Guid newListGuid = webSite.Lists.Add(listName, listDescription, listTemplate); list = webSite.Lists[newListGuid]; } return list; }
internal static bool CheckListForExist(string listName, SPWeb spWeb, SPListTemplateType listTemplateType, bool createList) { try { if (spWeb.Lists.TryGetList(listName) == null) { if (createList) { spWeb.AllowUnsafeUpdates = true; spWeb.Lists.Add(listName, string.Empty, listTemplateType); if (listName == "QuickPolls") { SPList newList = spWeb.Lists["QuickPolls"]; newList.Fields.Add("Question", SPFieldType.Text, true); newList.Fields.Add("Answers", SPFieldType.Note, true); newList.Fields.Add("Response", SPFieldType.Text, true); newList.Fields.Add("Expires", SPFieldType.DateTime, true); SPView view = newList.DefaultView; view.ViewFields.Add("Question"); view.ViewFields.Add("Answers"); view.ViewFields.Add("Response"); view.ViewFields.Add("Expires"); view.Update(); SPListItem newItem = newList.AddItem(); newItem["Title"] = "Favorite berry"; newItem["Question"] = "What is your favorite berry?"; newItem["Answers"] = "Strawberry\r\nBlackberry\r\nBlueberry\r\nHuckleberry\r\nRasberry"; newItem["Expires"] = DateTime.Today.AddYears(1); newItem.Update(); } } return true; } return false; } catch (Exception) { return false; } }
protected BaseListDefinition(SPListTemplateType templateType) : base() { _templateType = templateType; }
public static IEnumerable <TList> GetListsByInternalName <TList>(this SPListCollection lists, string internalName, SPBaseType baseType, SPListTemplateType templateType) where TList : SPList { return(lists.GetListsByInternalName <TList>(internalName, baseType).Where(l => l.BaseTemplate == templateType)); }
public static IEnumerable <TList> GetLists <TList>(this SPWeb web, SPBaseType baseType, SPListTemplateType templateType) where TList : SPList { return(web.GetLists <TList>(baseType).Where(lst => lst.BaseTemplate == templateType)); }
public Guid CreateList(out Boolean IsExisting, String strListName, String strDescription, ArrayList xmlFieldCollection, SPListTemplateType listType) { return(CreateList(out IsExisting, strListName, strDescription, xmlFieldCollection, listType, false)); }
public static IEnumerable <TList> GetListsByInternalName <TList>(this SPListCollection lists, string internalName, SPListTemplateType templateType) where TList : SPList { return(lists.GetLists <TList>(templateType).Where(l => l.RootFolder.Name == internalName)); }
public Guid CreateList(out Boolean IsExisting, String strListName, String strDescription, ArrayList xmlFieldCollection, SPListTemplateType listType, Boolean requireCheckout) { SPWeb objSPWeb = this.CurrentWeb; SPList objList; Guid objListGUID = default(Guid); IsExisting = false; try { if (!IsListExisting(strListName)) { //create list here objListGUID = objSPWeb.Lists.Add(strListName, strDescription, listType); objList = objSPWeb.Lists.GetList(objListGUID, false); if (requireCheckout) { objSPWeb.AllowUnsafeUpdates = true; objList.EnableVersioning = true; objList.EnableMinorVersions = true; objList.ForceCheckout = true; objList.EnableFolderCreation = false; objList.Update(); } } else { IsExisting = true; objList = objSPWeb.Lists.TryGetList(strListName); objListGUID = objList.ID; } foreach (String strfieldXML in xmlFieldCollection) { try { objList.Fields.AddFieldAsXml(strfieldXML, true, SPAddFieldOptions.AddFieldCheckDisplayName); } catch { } } } catch (Exception Ex) { throw Ex; } return(objListGUID); }
private static bool CreateSpList(SPWeb web, string listName, string description, bool showInQuickLaunch, SPListTemplateType type) { bool status = false; SPSecurity.RunWithElevatedPrivileges(delegate { using (var site = new SPSite(web.Url)) { SPWeb webLocal = site.AllWebs[web.ID]; SPList list; try { list = webLocal.Lists[listName]; status = true; } catch (Exception) { list = null; } if (list == null) { webLocal.Lists.Add(listName, description, type); webLocal.Update(); try { list = webLocal.Lists[listName]; if (showInQuickLaunch) { list.OnQuickLaunch = true; list.Update(); } status = true; } catch (Exception) { status = false; } } } }); return status; }
public ReadOnlyListDetails(string urlName, SPListTemplateType templateType, string title, string description, bool enforceUniqueValues) { _listDetails = new ListDetails(urlName, templateType, title, description, enforceUniqueValues); }
/// <summary> /// Gets or creates a list depending of the current isolation level. /// If the isolation level is integration or none the function loads the list from the current web (the url that was specified in the constructor). /// If the isolation level is fake a list will be added to the faked web instance. /// </summary> /// <param name="name">The name of the list.</param> /// <param name="type">The type (SPListTemplateType) of the list.</param> /// <param name="fields">An optional array of strings. For each value a text field will be added to the list.</param> /// <returns>The list instance.</returns> public virtual SPList GetOrCreateList(string name, SPListTemplateType type, params string[] fields) { if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); if (isolationLevel == IsolationLevel.Integration || isolationLevel == SPEmulators.IsolationLevel.None) { return web.Lists[name]; } else { var id = web.Lists.Add(name, string.Empty, type); var list = web.Lists[id]; if (fields.Length > 0) { Array.ForEach(fields, (s) => { list.Fields.Add(s, SPFieldType.Text, false); }); list.Update(); } return list; } }
public SPList CreateList(SPWeb webSite, string listName, string listDescription, SPListTemplateType listTemplate) { return SharePointUtilities.CreateList(webSite, listName, listDescription, listTemplate); }
public ListCustom(string name, SPListTemplateType listTemplateType, List<SPField> fields = null) { Name = name; ListTemplateType = listTemplateType; Fields = fields; }
public SPList EnsureList(SPWeb web, string name, string description, SPListTemplateType templateType) { var list = this.TryGetList(web, name); if (list != null) { // List already exists, check for correct template if (list.BaseTemplate != templateType) { throw new SPException(string.Format(CultureInfo.InvariantCulture, "List {0} has list template type {1} but should have list template type {2}.", name, list.BaseTemplate, templateType)); } } else { // Create new list var id = web.Lists.Add(name, description, templateType); list = web.Lists[id]; } return list; }
public static SPList EnsureList(this SPWeb web, string listTitle, string desc, SPListTemplateType lstTemplateType) { SPListCollection lstCollection = web.Lists; SPList lstObj = (from SPList lst in lstCollection where string.Equals(lst.Title, listTitle, StringComparison.InvariantCultureIgnoreCase) == true select lst).FirstOrDefault(); if (lstObj != null) { return lstObj; } Guid lstGuid = web.Lists.Add(listTitle, desc, lstTemplateType); try { SPList newList = web.Lists.GetList(lstGuid, true); newList.OnQuickLaunch = true; newList.Update(); return newList; } catch { return null; } }
public static IEnumerable <TList> GetLists <TList>(this SPListCollection lists, SPListTemplateType templateType) where TList : SPList { return(lists.OfType <TList>().Where(lst => lst.BaseTemplate == templateType)); }