// in this case we're not using the spweb in the base class in fact we're passing it as a parameter public void CreateList(SPWeb currentWebSite) { SPWeb website = null; try { website = currentWebSite ?? GetWebSite(); website.AllowUnsafeUpdates = true; SPListCollection lists = website.Lists; Guid idList = lists.Add(ListName, string.Empty, SPListTemplateType.GenericList); SPList list = lists.GetList(idList, false); list.NoCrawl = true; list.Update(); website.AllowUnsafeUpdates = false; } catch (Exception ex) { var log = new AppEventLog(AppException.ExceptionMessage(ex, "CreateList", "ClsHelper")); log.WriteToLog(); } finally { if (website != null) { website.Dispose(); } } }
public void createList() { try { using (SPSite site = new SPSite(ConfigurationManager.AppSettings["siteUrl"])) { using (SPWeb web = site.OpenWeb()) { SPListCollection lists = web.Lists; // create new Generic list called "My List" lists.Add(ConfigurationManager.AppSettings["listName"], "Task responses", SPListTemplateType.GenericList); SPList newList = web.Lists["Incoming Mail List"]; // create Text type new column called "My Column" newList.Fields.Add("Body", SPFieldType.Text, true); newList.Fields.Add("Sender", SPFieldType.Text, true); // make new column visible in default view SPView view = newList.DefaultView; view.ViewFields.Add("Body"); view.ViewFields.Add("Sender"); view.Update(); } } } catch (Exception ex) { throw ex; } }
public static Tuple <string, string> EnsureActivitiesList() { string currentSiteUrl = SPContext.Current.Site.Url; Tuple <string, string> result = null; SPSecurity.RunWithElevatedPrivileges(delegate() { try { using (SPSite site = new SPSite(currentSiteUrl)) using (SPWeb rootWeb = site.OpenWeb()) { rootWeb.AllowUnsafeUpdates = true; SPList extistingList = rootWeb.Lists.TryGetList(ActivityLoggerListTitle); if (extistingList != null) { result = Tuple.Create(extistingList.ID.ToString(), extistingList.DefaultView.ID.ToString()); return; } SPListCollection lists = rootWeb.Lists; lists.Add(ActivityLoggerListInternalName, "UPSBrowser logged activities", SPListTemplateType.GenericList); SPList list = rootWeb.Lists[ActivityLoggerListInternalName]; list.Title = ActivityLoggerListTitle; list.Fields.Add("RegisteredDate", SPFieldType.DateTime, true); list.Fields.Add("Initiator", SPFieldType.Text, true); list.Fields.Add("User", SPFieldType.Text, true); list.Fields.Add("Action", SPFieldType.Text, true); list.Fields.Add("Result", SPFieldType.Text, true); list.Fields.Add("AdditionalInfo", SPFieldType.Text, false); list.Update(); SPView view = list.DefaultView; view.ViewFields.Add("RegisteredDate"); view.ViewFields.Add("Initiator"); view.ViewFields.Add("User"); view.ViewFields.Add("Action"); view.ViewFields.Add("Result"); view.ViewFields.Add("AdditionalInfo"); view.Update(); rootWeb.AllowUnsafeUpdates = false; result = Tuple.Create(list.ID.ToString(), list.DefaultView.ID.ToString()); }; } catch (Exception e) { UPSBrowserLogger.LogError(loggingCategory, $"Error creating list '{ActivityLoggerListTitle}' in the root web at {currentSiteUrl}. Exception: {e.Message}"); return; }; }); return(result); }
public virtual void AddListTo(SPListCollection listCollection) { Guid guid = listCollection.Add(InitialName, Description, ListTemplateType); SPList list = listCollection[guid]; list.Title = Title; list.ContentTypesEnabled = ContentTypesEnabled; list.EnableVersioning = EnableVersioning; list.Update(); }
static void Main(string[] args) { string lookupFieldName = "RelatedField"; using (SPSite site = new SPSite("http://sharepointserve")) { using (SPWeb web = site.OpenWeb()) { SPListCollection lists = web.Lists; Guid SourceListId = lists.Add("Parent List", "", SPListTemplateType.GenericList); Console.WriteLine("Parent List Done..."); Guid TargetListId = lists.Add("Child List", "", SPListTemplateType.GenericList); Console.WriteLine("Child List Done..."); SPList SourceList = lists[SourceListId]; SPList TargetList = lists[TargetListId]; SPFieldCollection Fields = TargetList.Fields; Fields.AddLookup(lookupFieldName, SourceList.ID, true); Console.WriteLine("Lookup Field Created"); SPFieldLookup NewLookupField = Fields[lookupFieldName] as SPFieldLookup; NewLookupField.Indexed = true; NewLookupField.LookupField = "Title"; NewLookupField.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.Restrict; NewLookupField.Update(); Console.WriteLine("Lookup field integrity enforced"); SPListItem NewSourceItem = SourceList.Items.Add(); NewSourceItem["Title"] = "Parent Data"; NewSourceItem.Update(); Console.WriteLine("Source listitem created"); SPListItem NewTargetItem = TargetList.Items.Add(); NewTargetItem["Title"] = "Child Data"; NewTargetItem[lookupFieldName] = new SPFieldLookupValue(1, "Source Data"); NewTargetItem.Update(); Console.WriteLine("Parent listitem created"); TargetList.Update(); SourceList.Update(); } } Console.ReadLine(); }
/// <summary> /// 创建列表"workVideo" "workPic", "workFile" /// </summary> public static SPList CreateList(string listName) { SPListCollection col = DAL.Common.SPWeb.Lists; Guid guid; if (listName == "workPic") { guid = col.Add(listName, "", SPListTemplateType.PictureLibrary); } else { guid = col.Add(listName, "", SPListTemplateType.DocumentLibrary); } SPList list = col.GetList(guid, false); list.Hidden = true; list.Update(); return(list); }
protected void buttonCreateType_Click(object sender, EventArgs e) { //Here we will create a new content type and list //Start by getting the current web SPWeb web = SPContext.Current.Web; //Get the web's collection of content types SPContentTypeCollection contentTypes = web.ContentTypes; //Create a new content type SPContentType newType = new SPContentType(contentTypes[SPBuiltInContentTypeId.Announcement], contentTypes, "Contoso Announcements"); //Add it to the web try { contentTypes.Add(newType); } catch (SPException ex) { //This is probably because the content type already exists labelCreateTypeResult.Text = ex.Message; } //Now get the web's field collection and add a new field to it SPFieldCollection siteFields = web.Fields; try { siteFields.Add("Product", SPFieldType.Text, false); web.Update(); } catch (SPException ex) { //This is probably because the field already exists labelCreateTypeResult.Text = ex.Message; } //Add the field to the new content type newType.FieldLinks.Add(new SPFieldLink(siteFields["Product"])); newType.Update(); //Get the web's list collection SPListCollection lists = web.Lists; try { Guid newListGuid = lists.Add("Product Announcements", "Announcements about Contoso Products", SPListTemplateType.Announcements); SPList newList = lists[newListGuid]; newList.ContentTypes.Add(newType); newList.Update(); } catch (SPException ex) { //This is probably because the field already exists labelCreateTypeResult.Text = ex.Message; } labelCreateTypeResult.Text = "Contoso Announcement content type and Product Announcements list created successfully"; }
/// <summary> /// Adds a list to the specified list collection. /// </summary> /// <param name="lists">The lists collection to add the list to.</param> /// <param name="urlName">Name of the list to use in the URL.</param> /// <param name="title">The title of the list.</param> /// <param name="description">The description.</param> /// <param name="featureId">The feature id that the list template is associated with.</param> /// <param name="templateType">Type of the template.</param> /// <param name="docTemplateType">Type of the doc template.</param> /// <returns></returns> public static SPList Add( SPListCollection lists, string urlName, string title, string description, Guid featureId, int templateType, string docTemplateType) { if (docTemplateType == "") docTemplateType = null; Guid guid = lists.Add(title, description, urlName, featureId.ToString("D"), templateType, docTemplateType); return lists[guid]; }
private static SPList AddList(SPListCollection lists, string urlName, string title, string description, Guid featureId, Guid[] previousVersionFeatureIds, int templateType, out bool newListCreated) { SPList listIfExists = null; newListCreated = false; try { listIfExists = lists[title]; if (listIfExists == null) { listIfExists = lists.Web.GetList(urlName); } } catch (SPException ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); } catch (FileNotFoundException ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); } if (listIfExists != null) { bool flag = listIfExists.TemplateFeatureId.Equals(featureId); if ((!flag && (previousVersionFeatureIds != null)) && (previousVersionFeatureIds.Length > 0)) { foreach (Guid guid in previousVersionFeatureIds) { if (listIfExists.TemplateFeatureId.Equals(guid)) { flag = true; break; } } } } if (listIfExists == null) { Guid guid2 = lists.Add(title, description, urlName, featureId.ToString("D"), templateType, null); newListCreated = true; listIfExists = lists[guid2]; } return(listIfExists); }
protected void CreateList() { try { // choose your site SPWeb web = SPContext.Current.Web; SPListCollection lists = web.Lists; // create new Generic list called "AlertsList" lists.Add("AlertsList", "List to control the alerts for this webpart. Don't change the columns", SPListTemplateType.GenericList); SPList list = web.Lists["AlertsList"]; StringCollection categories = new StringCollection(); categories.AddRange(new string[] { "High", "Medium", "Low" }); // create Text type new column called "My Column" list.Fields.Add("Description", SPFieldType.Text, true); list.Fields.Add("Impact", SPFieldType.Choice, true, false, categories); list.Fields.Add("Pin to top", SPFieldType.Boolean, true); //get the newly added choice field instance SPFieldChoice fieldImpact = (SPFieldChoice)list.Fields["Impact"]; //set field format type i.e. radio/dropdown fieldImpact.EditFormat = SPChoiceFormatType.Dropdown; list.Update(); // make new column visible in default view SPView view = list.DefaultView; view.ViewFields.Add("Description"); view.ViewFields.Add("Impact"); view.ViewFields.Add("Pin to top"); view.Update(); Label myLabel = new Label(); myLabel.Text = "AlertsList Created. Please go to site contents to add items for the alerts"; this.Controls.Add(myLabel); } catch (Exception e) { } }
/// <summary> /// Adds a list to the specified list collection. /// </summary> /// <param name="lists">The lists collection to add the list to.</param> /// <param name="urlName">Name of the list to use in the URL.</param> /// <param name="title">The title of the list.</param> /// <param name="description">The description.</param> /// <param name="featureId">The feature id that the list template is associated with.</param> /// <param name="templateType">Type of the template.</param> /// <param name="docTemplateType">Type of the doc template.</param> /// <returns></returns> public static SPList Add( SPListCollection lists, string urlName, string title, string description, Guid featureId, int templateType, string docTemplateType) { if (docTemplateType == "") { docTemplateType = null; } Guid guid = lists.Add(title, description, urlName, featureId.ToString("D"), templateType, docTemplateType); return(lists[guid]); }
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(); }
/// <summary> /// Invoke on Feature Activation /// </summary> /// <param name="properties"></param> public override void FeatureActivated(SPFeatureReceiverProperties properties) { try { SPSite site = properties.Feature.Parent as SPSite; jobTitle = jobTitle + site.Url.ToString(); // Delete Existing Timer Job If Installed foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) { if (job.Name.Equals(jobTitle, StringComparison.InvariantCultureIgnoreCase)) { job.Delete(); } } AlertJobdefinition objArchivalJob = new AlertJobdefinition(jobTitle, site.WebApplication); SPMinuteSchedule schedule = new SPMinuteSchedule(); if (schedule != null) { schedule.BeginSecond = 0; schedule.EndSecond = 59; schedule.Interval = 30; objArchivalJob.Properties.Add(WebSiteURL_KeyName, site.Url); objArchivalJob.Schedule = schedule; objArchivalJob.Update(); } //Creating Hidden List1 SPWeb web = site.OpenWeb(); SPListCollection lists = web.Lists; lists.Add("CCSAdvancedAlertsList", "CrowCanyon Advanced Alerts List", SPListTemplateType.GenericList); SPList newList = web.Lists["CCSAdvancedAlertsList"]; newList.Fields.Add("WebID", SPFieldType.Text, false); newList.Fields.Add("ListID", SPFieldType.Text, false); newList.Fields.Add("ItemID", SPFieldType.Text, false); newList.Fields.Add("WhenToSend", SPFieldType.Choice, false); SPFieldChoice WhenToSendChoiceCol = (SPFieldChoice)newList.Fields["WhenToSend"]; string[] strdata = new string[3]; strdata[0] = "Immediate"; strdata[1] = "Daily"; strdata[2] = "Weekely"; WhenToSendChoiceCol.Choices.Add(strdata[0]); WhenToSendChoiceCol.Choices.Add(strdata[1]); WhenToSendChoiceCol.Choices.Add(strdata[2]); WhenToSendChoiceCol.Update(); newList.Fields.Add("DetailInfo", SPFieldType.Note, false); newList.Fields.Add("Owner", SPFieldType.User, false); newList.Fields.Add("EventType", SPFieldType.Choice, false); SPFieldChoice EventTypeChoiceCol = (SPFieldChoice)newList.Fields["EventType"]; string[] strdata1 = new string[4]; strdata1[0] = "ItemAdded"; strdata1[1] = "ItemUpdated"; strdata1[2] = "ItemDeleted"; strdata1[3] = "DateColumn"; EventTypeChoiceCol.Choices.Add(strdata1[0]); EventTypeChoiceCol.Choices.Add(strdata1[1]); EventTypeChoiceCol.Choices.Add(strdata1[2]); EventTypeChoiceCol.Choices.Add(strdata1[3]); EventTypeChoiceCol.Update(); newList.Fields.Add("SendDay", SPFieldType.Choice, false); SPFieldChoice SendDayChoiceCol = (SPFieldChoice)newList.Fields["SendDay"]; string[] strdata2 = new string[7]; strdata2[0] = "1"; strdata2[1] = "2"; strdata2[2] = "3"; strdata2[3] = "4"; strdata2[4] = "5"; strdata2[5] = "6"; strdata2[6] = "7"; SendDayChoiceCol.Choices.Add(strdata2[0]); SendDayChoiceCol.Choices.Add(strdata2[1]); SendDayChoiceCol.Choices.Add(strdata2[2]); SendDayChoiceCol.Choices.Add(strdata2[3]); SendDayChoiceCol.Choices.Add(strdata2[4]); SendDayChoiceCol.Choices.Add(strdata2[5]); SendDayChoiceCol.Choices.Add(strdata2[6]); SendDayChoiceCol.Update(); newList.Fields.Add("SendHour", SPFieldType.Choice, false); SPFieldChoice SendHourChoiceCol = (SPFieldChoice)newList.Fields["SendHour"]; string[] strdata3 = new string[24]; strdata3[0] = "0"; strdata3[1] = "1"; strdata3[2] = "2"; strdata3[3] = "3"; strdata3[4] = "4"; strdata3[5] = "5"; strdata3[6] = "6"; strdata3[7] = "7"; strdata3[8] = "8"; strdata3[9] = "9"; strdata3[10] = "10"; strdata3[11] = "11"; strdata3[12] = "12"; strdata3[13] = "13"; strdata3[14] = "14"; strdata3[15] = "15"; strdata3[16] = "16"; strdata3[17] = "17"; strdata3[18] = "18"; strdata3[19] = "19"; strdata3[20] = "20"; strdata3[21] = "21"; strdata3[22] = "22"; strdata3[23] = "23"; SendHourChoiceCol.Choices.Add(strdata3[0]); SendHourChoiceCol.Choices.Add(strdata3[1]); SendHourChoiceCol.Choices.Add(strdata3[2]); SendHourChoiceCol.Choices.Add(strdata3[3]); SendHourChoiceCol.Choices.Add(strdata3[4]); SendHourChoiceCol.Choices.Add(strdata3[5]); SendHourChoiceCol.Choices.Add(strdata3[6]); SendHourChoiceCol.Choices.Add(strdata3[7]); SendHourChoiceCol.Choices.Add(strdata3[8]); SendHourChoiceCol.Choices.Add(strdata3[9]); SendHourChoiceCol.Choices.Add(strdata3[10]); SendHourChoiceCol.Choices.Add(strdata3[11]); SendHourChoiceCol.Choices.Add(strdata3[12]); SendHourChoiceCol.Choices.Add(strdata3[13]); SendHourChoiceCol.Choices.Add(strdata3[14]); SendHourChoiceCol.Choices.Add(strdata3[15]); SendHourChoiceCol.Choices.Add(strdata3[16]); SendHourChoiceCol.Choices.Add(strdata3[17]); SendHourChoiceCol.Choices.Add(strdata3[18]); SendHourChoiceCol.Choices.Add(strdata3[19]); SendHourChoiceCol.Choices.Add(strdata3[20]); SendHourChoiceCol.Choices.Add(strdata3[21]); SendHourChoiceCol.Choices.Add(strdata3[22]); SendHourChoiceCol.Choices.Add(strdata3[23]); SendHourChoiceCol.Update(); SPView view = newList.DefaultView; view.ViewFields.Add("WebID"); view.ViewFields.Add("ListID"); view.ViewFields.Add("ItemID"); view.ViewFields.Add("WhenToSend"); view.ViewFields.Add("DetailInfo"); view.ViewFields.Add("Owner"); view.ViewFields.Add("EventType"); view.ViewFields.Add("SendDay"); view.ViewFields.Add("SendHour"); view.Update(); newList.Hidden = true; newList.Update(); //Creating Hidden List2 lists.Add("CCSAdvancedAlertsMailTemplates", "CrowCanyon Advanced Alerts Mail Templates", SPListTemplateType.GenericList); SPList newList2 = web.Lists["CCSAdvancedAlertsMailTemplates"]; newList2.Fields.Add("InsertUpdatedFields", SPFieldType.Boolean, false); newList2.Fields.Add("HighLightUpdatedFields", SPFieldType.Boolean, false); newList2.Fields.Add("InsertAttachments", SPFieldType.Boolean, false); newList2.Fields.Add("Owner", SPFieldType.User, false); newList2.Fields.Add("Subject", SPFieldType.Text, false); newList2.Fields.Add("Body", SPFieldType.Note, false); SPView view2 = newList2.DefaultView; view2.ViewFields.Add("InsertUpdatedFields"); view2.ViewFields.Add("HighLightUpdatedFields"); view2.ViewFields.Add("InsertAttachments"); view2.ViewFields.Add("Owner"); view2.ViewFields.Add("Subject"); view2.ViewFields.Add("Body"); view2.Update(); newList2.Hidden = true; newList2.Update(); // Creating Hidden List3 lists.Add("CCSAdvancedTemplateForAlert", "CrowCanyon Advanced Template for alert", SPListTemplateType.GenericList); SPList newList3 = web.Lists["CCSAdvancedTemplateForAlert"]; newList3.Fields.AddLookup("Template", newList2.ID, false); SPFieldLookup lkp = (SPFieldLookup)newList3.Fields["Template"]; lkp.LookupField = newList2.Fields["Title"].InternalName; newList3.Fields.Add("EventType", SPFieldType.Choice, false); SPFieldChoice EventTypeChoiceCol2 = (SPFieldChoice)newList3.Fields["EventType"]; string[] strdata4 = new string[4]; strdata4[0] = "ItemAdded"; strdata4[1] = "ItemUpdated"; strdata4[2] = "ItemDeleted"; strdata4[3] = "DateColumn"; EventTypeChoiceCol2.Choices.Add(strdata4[0]); EventTypeChoiceCol2.Choices.Add(strdata4[1]); EventTypeChoiceCol2.Choices.Add(strdata4[2]); EventTypeChoiceCol2.Choices.Add(strdata4[3]); EventTypeChoiceCol2.Update(); newList3.Fields.Add("InsertUpdatedFields", SPFieldType.Boolean, false); newList3.Fields.Add("HighLightUpdatedFields", SPFieldType.Boolean, false); newList3.Fields.Add("InsertAttachments", SPFieldType.Boolean, false); newList3.Fields.AddLookup("Alert", newList.ID, false); SPFieldLookup lkp2 = (SPFieldLookup)newList3.Fields["Alert"]; lkp2.LookupField = newList.Fields["Title"].InternalName; newList3.Update(); SPView view3 = newList3.DefaultView; view3.ViewFields.Add("Template"); view3.ViewFields.Add("EventType"); view3.ViewFields.Add("InsertUpdatedFields"); view3.ViewFields.Add("HighLightUpdatedFields"); view3.ViewFields.Add("InsertAttachments"); view3.ViewFields.Add("Alert"); view3.Update(); newList3.Hidden = true; newList3.Update(); //Creating Hidden List 4 lists.Add("CCSAdvancedDelayedAlerts", "CrowCanyon Advanced Delayed Alerts", SPListTemplateType.GenericList); SPList newList4 = web.Lists["CCSAdvancedDelayedAlerts"]; newList4.Fields.Add("Subject", SPFieldType.Text, false); newList4.Fields.Add("Body", SPFieldType.Note, false); newList4.Fields.Add("EventType", SPFieldType.Choice, false); SPFieldChoice EventTypeChoiceCol3 = (SPFieldChoice)newList4.Fields["EventType"]; string[] strdata5 = new string[4]; strdata5[0] = "ItemAdded"; strdata5[1] = "ItemUpdated"; strdata5[2] = "ItemDeleted"; strdata5[3] = "DateColumn"; EventTypeChoiceCol3.Choices.Add(strdata5[0]); EventTypeChoiceCol3.Choices.Add(strdata5[1]); EventTypeChoiceCol3.Choices.Add(strdata5[2]); EventTypeChoiceCol3.Choices.Add(strdata5[3]); EventTypeChoiceCol3.Update(); newList4.Fields.AddLookup("Alert", newList.ID, false); SPFieldLookup lkp3 = (SPFieldLookup)newList4.Fields["Alert"]; lkp3.LookupField = newList.Fields["Title"].InternalName; newList4.Fields.Add("ItemID", SPFieldType.Text, false); newList4.Update(); SPView view4 = newList4.DefaultView; view4.ViewFields.Add("Subject"); view4.ViewFields.Add("Body"); view4.ViewFields.Add("EventType"); view4.ViewFields.Add("Alert"); view4.ViewFields.Add("ItemID"); view4.Update(); newList4.Hidden = true; newList4.Update(); } catch (System.Exception Ex) { } }
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)); }