private void Delete( SPList list, int parentMessageId, string internalName, string listValue, bool deleteIfNoList, SPField spField) { if (list == null) { throw new ArgumentNullException(nameof(list)); } if (deleteIfNoList && spField != null) { try { spField.Delete(); list.Update(); addMessage(ErrorLevels.Upgrade, internalName, $"Lookup List missing ({listValue}) field deleted", parentMessageId); } catch (Exception ex) { addMessage(ErrorLevels.Error, internalName, $"Lookup List missing ({listValue}) field failed to delete: " + ex.Message, parentMessageId); Trace.WriteLine(ex.ToString()); } } else { addMessage(ErrorLevels.Upgrade, internalName, $"Lookup List missing ({listValue}) field ignored", parentMessageId); } }
private static bool TryDeleteField(SPList list, string InternalName) { SPField field = null; try { field = list.Fields.GetFieldByInternalName(InternalName); } catch { } if (field != null) { try { if (field.Sealed) { field.Sealed = false; field.Update(); } field.Delete(); list.Update(); return(true); } catch { return(false); } } else { return(true); } }
private void deleteWebPeriod(SPWeb web, string period, string url) { try { if (CoreFunctions.getConfigSetting(web, "EPMLiveTimePhasedURL").ToLower() == url.ToLower()) { SPList list = web.Lists["EPMLiveTimePhased"]; SPField f = list.Fields.GetFieldByInternalName(period.Replace(" ", "_x0020_")); f.Delete(); } } catch { } foreach (SPWeb w in web.Webs) { try { deleteWebPeriod(w, period, url); } catch (Exception ex) { LoggingService.WriteTrace(Area.EPMLiveCore, Categories.EPMLiveCore.Others, TraceSeverity.Medium, ex.ToString()); } finally { if (w != null) { w.Dispose(); } } } }
private void lnkDeleteSourceColumns_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { rtbDisplay.Clear(); //TODO: redo to just display a form with checkboxes to delete columns, listing all content types besides target content type and folder content type. if (cboMappingProfile.SelectedItem == null) { return; } SPList list = (SPList)cboDocLibs.SelectedItem; MappingProfile mp = (MappingProfile)cboMappingProfile.SelectedItem; //-- AddToRtbLocal("Deleting source columns from document library\r\n", StyleType.titleSeagreen); if (!findColoumRefFromInternalName(mp, list)) { return; } DialogResult ret = MessageBox.Show(this, "Are you sure you want to delete these " + mp.MappingItems.Count + " columns?", "SUSHI", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { foreach (MappingItem mi in mp.MappingItems) { SPField field = list.Fields[mi.sourceID]; if (field.CanBeDeleted == false) { SmartStepUtil.AddToRTB(rtbDisplay, "can't delete source column " + mi.SourceColumn + ", because it is an undeletable column\r\n"); } else { SmartStepUtil.AddToRTB(rtbDisplay, "deleting source column " + mi.SourceColumn); field.Delete(); SmartStepUtil.AddToRTB(rtbDisplay, " done. \r\n", StyleType.bodyBlackBold); } } } }
public static bool RemoveField(SPField spField) { bool res = false; try { if (spField == null) { return res; } // check if it's a ReadOnly field. // if so, reset it if (spField.ReadOnlyField) { spField.ReadOnlyField = false; spField.Update(); } // check if it's a Hidden field. // if so, reset it if (spField.Hidden) { spField.Hidden = false; spField.Update(); } // check if the AllowDeletion property is set to false. // if so, reset it to true if (spField.AllowDeletion == null || !spField.AllowDeletion.Value) { spField.AllowDeletion = true; spField.Update(); } // finally, remove the field spField.Delete(); spField.ParentList.Update(); res = true; } catch (Exception ex) { UlsLogging.LogError("ListField. RemoveField(SPField spField). Message: {0}, StackTrace: {1}", ex.Message, ex.StackTrace); } return res; }
public override bool Perform() { storeurl = CoreFunctions.getFarmSetting("workenginestore"); solutions = (SPDocumentLibrary)base.SPWeb.Site.GetCatalog(SPListTemplateType.ListTemplateCatalog); LogMessage("Activating List Features"); SPSite.Features.Add(new Guid("e08e676e-81fb-497e-9590-9d1c2673b85c"), true); //============================================================== LogMessage("Removing old settings list"); try { SPList settings = SPWeb.Lists.TryGetList("EPM Live Settings"); if (settings != null) { settings.Delete(); } } catch (Exception ex) { LogMessage("", ex.Message, 3); } //============================================================== LogMessage("Downloading and Installing List Templates"); DownloadAndInstallList("Departments", "Departments", "Departments"); DownloadAndInstallList("HolidaySchedules", "HolidaySchedules", "Holiday Schedules"); DownloadAndInstallList("Holidays", "Holidays", "Holidays"); if (base.bIsPfe) { DownloadAndInstallList("EPM Live Settings", "pfe epm live settings", "EPM Live Settings"); } else { DownloadAndInstallList("EPM Live Settings", "epm live settings", "EPM Live Settings"); } DownloadAndInstallList("Roles", "Roles", "Roles"); DownloadAndInstallList("WorkHours", "WorkHours", "Work Hours"); DownloadAndInstallList("Time Off", "TimeOff", "Time Off"); //============================================================== LogMessage("Checking Holidays Lookup"); SPList oHolidays = SPWeb.Lists.TryGetList("Holidays"); SPList oHolidaySchedules = SPWeb.Lists.TryGetList("Holiday Schedules"); SPList oResourcePool = SPWeb.Lists.TryGetList("Resources"); if (oHolidays == null) { LogMessage("", "Holidays list missing", 3); } else if (oHolidaySchedules == null) { LogMessage("", "Holiday Schedules list missing", 3); } else { SPField oField = null; try { oField = oHolidays.Fields.GetFieldByInternalName("HolidaySchedule"); } catch { } if (oField == null) { LogMessage("\tCreating Holidays Lookup"); oField = oHolidays.Fields.GetFieldByInternalName(oHolidays.Fields.AddLookup("HolidaySchedule", oHolidaySchedules.ID, true)); oField.Title = "Holiday Schedule"; oField.Update(); var spFieldLookup = (SPFieldLookup)oField; spFieldLookup.LookupField = "Title"; spFieldLookup.Update(); } else { LogMessage("\tUpdating Holidays Lookup"); SPFieldLookup oLookup = (SPFieldLookup)oField; if (new Guid(oLookup.LookupList) != oHolidaySchedules.ID) { oField.Delete(); oHolidays.Update(); oField = oHolidays.Fields.GetFieldByInternalName(oHolidays.Fields.AddLookup("HolidaySchedule", oHolidaySchedules.ID, true)); oField.Title = "Holiday Schedule"; oField.Update(); var spFieldLookup = (SPFieldLookup)oField; spFieldLookup.LookupField = "Title"; spFieldLookup.Update(); } } oHolidays.Update(); } //Fixing Department Lookup SPList oDepartments = SPWeb.Lists.TryGetList("Departments"); if (oDepartments == null) { LogMessage("", "Departments list missing", 3); } else { LogMessage("Departments list lookups"); try { SPFieldLookup lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("RBS"); if (new Guid(lookup.LookupList) != oDepartments.ID) { bool bSealed = lookup.Sealed; if (bSealed) { lookup.Sealed = false; lookup.Update(); } lookup.AllowDeletion = true; lookup.Update(); lookup.Delete(); oDepartments.Fields.AddLookup("RBS", oDepartments.ID, false); lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("RBS"); lookup.LookupField = "DisplayName"; lookup.Title = "Parent Department"; lookup.Update(); if (bSealed) { lookup.Sealed = true; lookup.Update(); } LogMessage("\tField RBS"); } } catch (Exception ex) { LogMessage("", "Field RBS: " + ex.Message, 3); } try { SPFieldLookup lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("Managers"); if (new Guid(lookup.LookupList) != oResourcePool.ID) { bool bSealed = lookup.Sealed; if (bSealed) { lookup.Sealed = false; lookup.Update(); } lookup.AllowDeletion = true; lookup.Update(); lookup.Delete(); oDepartments.Fields.AddLookup("Managers", oResourcePool.ID, true); lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("Managers"); lookup.LookupField = "Title"; lookup.Update(); if (bSealed) { lookup.Sealed = true; lookup.Update(); } LogMessage("\tField Managers"); } } catch (Exception ex) { LogMessage("", "Field Managers: " + ex.Message, 3); } try { SPFieldLookup lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("Executives"); if (new Guid(lookup.LookupList) != oResourcePool.ID) { bool bSealed = lookup.Sealed; if (bSealed) { lookup.Sealed = false; lookup.Update(); } lookup.AllowDeletion = true; lookup.Update(); lookup.Delete(); oDepartments.Fields.AddLookup("Executives", oResourcePool.ID, false); lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("Executives"); lookup.LookupField = "Title"; lookup.Update(); if (bSealed) { lookup.Sealed = true; lookup.Update(); } LogMessage("\tField Executives"); } } catch (Exception ex) { LogMessage("", "Field Executives: " + ex.Message, 3); } } LogMessage("Processing Time Off Temp Data"); SPList oNonWork = SPWeb.Lists.TryGetList("Non Work"); SPList oTimeOff = SPWeb.Lists.TryGetList("Time Off"); if (oNonWork == null) { LogMessage("", "Non Work list missing", 3); } else if (oTimeOff == null) { LogMessage("", "Time Off list missing", 3); } else { if (!oTimeOff.Fields.ContainsFieldWithInternalName("TempType")) { oTimeOff.Fields.Add("TempType", SPFieldType.Text, false); oTimeOff.Update(); try { SPField oField = oTimeOff.Fields.GetFieldByInternalName("TempType"); oField.ShowInDisplayForm = false; oField.ShowInEditForm = false; oField.ShowInNewForm = false; oField.Update(); } catch { } } SPField oTimeOffType = null; try { oTimeOffType = oTimeOff.Fields.GetFieldByInternalName("TimeOffType"); } catch { } if (oTimeOffType != null && oTimeOffType.Type == SPFieldType.Choice) { LogMessage("\tProcessing Temp Items"); foreach (SPListItem li in oTimeOff.Items) { try { li["TempType"] = li[oTimeOffType.Id].ToString(); li.Update(); } catch (Exception ex) { LogMessage("\t", li.Title + ": " + ex.Message, 3); } } } SPField oWorkDetail = null; try { oWorkDetail = oTimeOff.Fields.GetFieldByInternalName("WorkDetail"); } catch { } if (oWorkDetail == null) { try { oTimeOff.Fields.AddFieldAsXml(@"<Field Type=""DaysHoursBreakdownField"" DisplayName=""WorkDetail"" Required=""FALSE"" EnforceUniqueValues=""FALSE"" StaticName=""WorkDetail"" Name=""WorkDetail"" ><Customization><ArrayOfProperty><Property><Name>StartDateField</Name><Value xmlns:q1=""http://www.w3.org/2001/XMLSchema"" p4:type=""q1:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">StartDate</Value></Property><Property><Name>FinishDateField</Name><Value xmlns:q2=""http://www.w3.org/2001/XMLSchema"" p4:type=""q2:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">DueDate</Value></Property><Property><Name>HoursField</Name><Value xmlns:q3=""http://www.w3.org/2001/XMLSchema"" p4:type=""q3:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">Work</Value></Property><Property><Name>HolidaySchedulesField</Name><Value xmlns:q4=""http://www.w3.org/2001/XMLSchema"" p4:type=""q4:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">HolidaySchedule</Value></Property><Property><Name>ResourcePoolList</Name><Value xmlns:q5=""http://www.w3.org/2001/XMLSchema"" p4:type=""q5:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">Resources</Value></Property><Property><Name>WorkHoursList</Name><Value xmlns:q6=""http://www.w3.org/2001/XMLSchema"" p4:type=""q6:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">Work Hours</Value></Property><Property><Name>HolidaysList</Name><Value xmlns:q7=""http://www.w3.org/2001/XMLSchema"" p4:type=""q7:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">Holidays</Value></Property></ArrayOfProperty></Customization></Field>"); SPField oField = oTimeOff.Fields.GetFieldByInternalName("WorkDetail"); oField.Title = "Work Detail"; oField.Update(); LogMessage("\tAdd Work Detail Field"); } catch (Exception ex) { LogMessage("", "Add Work Detail: " + ex.Message, 3); } } } try { if (!oResourcePool.Fields.ContainsFieldWithInternalName("EXTID")) { oResourcePool.Fields.Add("EXTID", SPFieldType.Text, false); SPField oField = oResourcePool.Fields.GetFieldByInternalName("EXTID"); oField.Hidden = true; oField.Update(); LogMessage("Add EXTID Field to Resources"); } } catch (Exception ex) { LogMessage("", "Add EXTID Field to Resources: " + ex.Message, 3); } //Process dept event LogMessage("Processing Department Events"); try { bool badding = false; bool bupdating = false; bool bdeleted = false; string sClass = "EPMLiveCore.DepartmentEvent"; string sAssembly = "EPM Live Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5"; foreach (SPEventReceiverDefinition e in oDepartments.EventReceivers) { if (e.Assembly == sAssembly && e.Class == sClass) { if (e.Type == SPEventReceiverType.ItemAdding) { badding = true; } else if (e.Type == SPEventReceiverType.ItemUpdating) { bupdating = true; } else if (e.Type == SPEventReceiverType.ItemDeleted) { bdeleted = true; } } } if (!badding) { oDepartments.EventReceivers.Add(SPEventReceiverType.ItemAdding, sAssembly, sClass); oDepartments.Update(); } if (!bupdating) { oDepartments.EventReceivers.Add(SPEventReceiverType.ItemUpdating, sAssembly, sClass); oDepartments.Update(); } if (!bdeleted) { oDepartments.EventReceivers.Add(SPEventReceiverType.ItemDeleted, sAssembly, sClass); oDepartments.Delete(); } } catch (Exception ex) { LogMessage("", ex.Message, 3); } LogMessage("Mapping Reporting lists."); var reportData = new ReportData(SPSite.ID); DataTable dbMappings = reportData.GetDbMappings(); if (!dbMappings.Select(string.Format("SiteId = '{0}'", SPSite.ID)).Any()) { LogMessage("", "Reporting is not configured.", 2); } else { try { var reportBiz = new ReportBiz(SPSite.ID, SPSite.WebApplication.Id); reportBiz.GetDatabaseMappings(); foreach (var list in new[] { "Work Hours", "Holiday Schedules", "Holidays", "Time Off" }) { try { LogMessage("Mapping " + list + " list to Reporting."); SPList spList = SPWeb.Lists[list]; ListBiz listBiz = reportBiz.CreateListBiz(spList.ID); if (string.IsNullOrEmpty(listBiz.ListName)) { reportBiz.CreateListBiz(spList.ID); LogMessage("", "Mapped successfully.", 1); } else { LogMessage("", "Already mapped.", 2); } } catch (Exception ex) { LogMessage("", ex.Message, 3); } } } catch (Exception ex) { LogMessage("", ex.Message, 3); } } return(true); }
public static void AddPermissionModuleCategoryVNToList(string siteUrl) { if (!string.IsNullOrEmpty(siteUrl)) { string colName = "PermissionModuleCategoryVN"; string listName = "Permission Group"; try { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite spSite = new SPSite(siteUrl)) { using (SPWeb spWeb = spSite.RootWeb) { SPList spList = spWeb.Lists.TryGetList(listName); if (spList != null) { spWeb.AllowUnsafeUpdates = true; Console.WriteLine(); SPField permissionModuleCategoryVN = spList.Fields.TryGetFieldByStaticName(colName); if (permissionModuleCategoryVN != null) { Console.Write(" -> Deleting..."); permissionModuleCategoryVN.Delete(); spList.Update(); Console.WriteLine(); Console.Write(" -> Deleted Successfully"); } else { Console.Write(" -> Not existed"); } Console.WriteLine(); Console.Write("Adding new column..."); SPList moduleCategoryList = spWeb.Lists.TryGetList("Module Category"); spList.Fields.AddFieldAsXml(@"<Field ID='{26667307-80F2-463D-871C-169CF294972D}' Name='PermissionModuleCategoryVN' FieldRef='b7b03ecb-aebb-4c01-9a90-a5b6ca24ea52' DisplayName='PermissionModuleCategoryVN' Type='Lookup' List='" + moduleCategoryList.ID.ToString() + "' ShowField='CommonName1066'></Field>", false, SPAddFieldOptions.AddToDefaultContentType); spList.Update(); SPField theField = spList.Fields[new Guid("{26667307-80F2-463D-871C-169CF294972D}")]; theField.SchemaXml = @"<Field ID='{26667307-80F2-463D-871C-169CF294972D}' Name='PermissionModuleCategoryVN' FieldRef='b7b03ecb-aebb-4c01-9a90-a5b6ca24ea52' DisplayName='$Resources:RBVHStadaLists,ModuleCategory_NameVietnamese;' Type='Lookup' List='" + moduleCategoryList.ID.ToString() + "' ShowField='CommonName1066'></Field>"; theField.Update(); Console.WriteLine(); Console.Write(" -> Done"); spWeb.AllowUnsafeUpdates = false; } else { Console.WriteLine(); Console.Write("Cannot find list: {0}", listName); } } } }); } catch (Exception ex) { Console.WriteLine(string.Format("Error: {0}", ex.Message)); } } else { Console.Write("Troll?"); Console.Read(); } }
public void Delete() { m_field.Delete(); }
/// <summary> /// Runs the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; SPBinaryParameterValidator.Validate("fielddisplayname", Params["fielddisplayname"].Value, "fieldinternalname", Params["fieldinternalname"].Value); string url = Params["url"].Value; string fieldTitle = Params["fielddisplayname"].Value; string fieldName = Params["fieldinternalname"].Value; bool useTitle = Params["fielddisplayname"].UserTypedIn; bool useName = Params["fieldinternalname"].UserTypedIn; bool force = Params["force"].UserTypedIn; SPField field = Utilities.GetField(url, fieldName, fieldTitle, useName, useTitle); if (field.ReadOnlyField && force) { field.ReadOnlyField = false; field.Update(); } if (!field.CanBeDeleted) { if (field.FromBaseType) { throw new Exception( "The field is derived from a base type and cannot be deleted. You must delete the field from the base type."); } else if (field.Sealed) { if (force) { field.Sealed = false; field.Update(); } else { throw new Exception("This field is sealed and cannot be deleted - specify \"-force\" to ignore this setting and attempt deletion regardless."); } } else if (field.AllowDeletion.HasValue && !field.AllowDeletion.Value && !force) { throw new Exception( "Field is marked as not allowing deletion - specify \"-force\" to ignore this setting and attempt deletion regardless."); } else if (field.AllowDeletion.HasValue && !field.AllowDeletion.Value && force) { field.AllowDeletion = true; field.Update(); } else { throw new Exception("Field cannot be deleted."); } } if (field.Hidden) { if (force) { if (field.CanToggleHidden) { field.Hidden = false; field.Update(); } else { MethodInfo setFieldBoolValue = field.GetType().GetMethod("SetFieldBoolValue", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, new Type[] { typeof(string), typeof(bool) }, null); //field.SetFieldBoolValue("Hidden", false); setFieldBoolValue.Invoke(field, new object[] { "Hidden", false }); //field.SetFieldBoolValue("CanToggleHidden", true); setFieldBoolValue.Invoke(field, new object[] { "CanToggleHidden", true }); field.Update(); } } else { throw new Exception( "You cannot delete hidden fields - specify \"-force\" to ignore this restriction and attempt deletion regardless."); } } field.Delete(); return((int)ErrorCodes.NoError); }
public override bool Perform() { LogMessage("Processing Time Off Data"); SPList oNonWork = SPWeb.Lists.TryGetList("Non Work"); SPList oTimeOff = SPWeb.Lists.TryGetList("Time Off"); if (oNonWork == null) { LogMessage("", "Non Work list missing", 3); } else if (oTimeOff == null) { LogMessage("", "Time Off list missing", 3); } else { SPField oTimeOffType = null; try { oTimeOffType = oTimeOff.Fields.GetFieldByInternalName("TimeOffType"); } catch (Exception ex) { LogMessage("", ex.Message, 3); return(true); } if (oTimeOffType.Type == SPFieldType.Choice) { if (oTimeOffType.Sealed) { oTimeOffType.Sealed = false; oTimeOffType.Update(); } oTimeOffType.AllowDeletion = true; oTimeOffType.Update(); oTimeOffType.Delete(); oTimeOff.Fields.AddLookup("TimeOffType", oNonWork.ID, true); SPFieldLookup oTimeOffTypeL = (SPFieldLookup)oTimeOff.Fields.GetFieldByInternalName("TimeOffType"); oTimeOffTypeL.LookupField = "Title"; oTimeOffTypeL.Sealed = true; oTimeOffTypeL.Title = "Time Off Type"; oTimeOffTypeL.Update(); try { oTimeOffType = oTimeOff.Fields.GetFieldByInternalName("TimeOffType"); } catch { } } if (oTimeOffType.Type == SPFieldType.Lookup) { DataTable dt = oNonWork.Items.GetDataTable(); foreach (SPListItem li in oTimeOff.Items) { try { DataRow[] dr = dt.Select("Title='" + li["TempType"].ToString() + "'"); if (dr.Length > 0) { SPFieldLookupValue lv = new SPFieldLookupValue(int.Parse(dr[0]["ID"].ToString()), li["TempType"].ToString()); li[oTimeOffType.Id] = lv; li.Update(); LogMessage("\tUpdate: " + li.Title); } } catch (Exception ex) { LogMessage("\t", "Update: " + li.Title + ": " + ex.Message, 3); } } } } return(true); }
private void ProcessFields(ref SPList oResourcePool) { try { if (oResourcePool.Fields.ContainsFieldWithInternalName("CanLogin")) { LogMessage("\tRemoving CanLogin field"); SPField oField = oResourcePool.Fields.GetFieldByInternalName("CanLogin"); if (oField.Sealed) { oField.Sealed = false; oField.Update(); } oField.AllowDeletion = true; oField.Update(); oField.Delete(); } } catch (Exception ex) { LogMessage("\t", "Removing CanLogin field: " + ex.Message, 3); } try { if (oResourcePool.Fields.ContainsFieldWithInternalName("DepartmentManager")) { LogMessage("\tRemoving Department Manager field"); SPField oField = oResourcePool.Fields.GetFieldByInternalName("DepartmentManager"); if (oField.Sealed) { oField.Sealed = false; oField.Update(); } oField.AllowDeletion = true; oField.Update(); oField.Delete(); } } catch (Exception ex) { LogMessage("\t", "Removing DepartmentManager field: " + ex.Message, 3); } try { if (!oResourcePool.Fields.ContainsFieldWithInternalName("ResourceLevel")) { LogMessage("\tAdding License Type field"); string sField = oResourcePool.Fields.AddFieldAsXml( @"<Field Type=""ResourceLevels"" DisplayName=""ResourceLevel"" Required=""FALSE"" EnforceUniqueValues=""FALSE"" StaticName=""ResourceLevel"" Name=""ResourceLevel"" AllowDeletion=""FALSE"" Description=""Choose the license type that this resource will require within EPM Live. The licence type selected will determine the features available to this resource.""/>"); SPField oField = oResourcePool.Fields.GetFieldByInternalName("ResourceLevel"); oField.Title = "License Type"; oField.Sealed = true; oField.Update(); } } catch (Exception ex) { LogMessage("\t", "Adding License Type field: " + ex.Message, 3); } try { if (!oResourcePool.Fields.ContainsFieldWithInternalName("HolidaySchedule")) { LogMessage("\tAdding Holiday Schedule field"); SPList oHolidaySchedules = SPWeb.Lists.TryGetList("Holiday Schedules"); if (oHolidaySchedules != null) { oResourcePool.Fields.AddLookup("HolidaySchedule", oHolidaySchedules.ID, true); var oField = (SPFieldLookup)oResourcePool.Fields.GetFieldByInternalName("HolidaySchedule"); oField.LookupField = "Title"; oField.Title = "Holiday Schedule"; oField.Update(); } else { LogMessage("\t", "Holiday schedule list missing", 3); } } } catch (Exception ex) { LogMessage("\t", "Adding Holiday Schedule field: " + ex.Message, 3); } try { if (!oResourcePool.Fields.ContainsFieldWithInternalName("WorkHours")) { LogMessage("\tAdding Work Hours field"); SPList oWorkHours = SPWeb.Lists.TryGetList("Work Hours"); if (oWorkHours != null) { oResourcePool.Fields.AddLookup("WorkHours", oWorkHours.ID, true); var oField = (SPFieldLookup)oResourcePool.Fields.GetFieldByInternalName("WorkHours"); oField.LookupField = "Title"; oField.Title = "Work Hours"; oField.Update(); } else { LogMessage("\t", "WorkHours list missing", 3); } } } catch (Exception ex) { LogMessage("\t", "Adding Work Hours field: " + ex.Message, 3); } try { if (!oResourcePool.Fields.ContainsFieldWithInternalName("Role")) { LogMessage("\tAdding Role field"); SPList oRoles = SPWeb.Lists.TryGetList("Roles"); if (oRoles != null) { oResourcePool.Fields.AddLookup("Role", oRoles.ID, true); if (bIsPfe) { var oField = (SPFieldLookup)oResourcePool.Fields.GetFieldByInternalName("Role"); oField.LookupField = "CCRName"; oField.Update(); } else { var oField = (SPFieldLookup)oResourcePool.Fields.GetFieldByInternalName("Role"); oField.LookupField = "Title"; oField.Update(); } } else { LogMessage("\t", "Roles list missing", 3); } } else { SPField oRoleField = oResourcePool.Fields.GetFieldByInternalName("Role"); if (oRoleField.Type != SPFieldType.Lookup) { LogMessage("\tReplacing Role field"); SPList oRoles = SPWeb.Lists.TryGetList("Roles"); if (oRoles != null) { if (oRoleField.Sealed) { oRoleField.Sealed = false; oRoleField.Update(); } oRoleField.AllowDeletion = true; oRoleField.Update(); oRoleField.Delete(); string sField = oResourcePool.Fields.AddLookup("Role", oRoles.ID, true); if (bIsPfe) { var oField = (SPFieldLookup)oResourcePool.Fields.GetFieldByInternalName(sField); oField.LookupField = "CCRName"; oField.Update(); } else { var oField = (SPFieldLookup)oResourcePool.Fields.GetFieldByInternalName(sField); oField.LookupField = "Title"; oField.Update(); } } else { LogMessage("\t", "Roles list missing", 3); } } } } catch (Exception ex) { LogMessage("\t", "Adding Role field: " + ex.Message, 3); } try { if (!oResourcePool.Fields.ContainsFieldWithInternalName("Department")) { LogMessage("\tAdding Department field"); SPList oDepts = oResourcePool.ParentWeb.Lists.TryGetList("Departments"); if (oDepts != null) { oResourcePool.Fields.AddLookup("Department", oDepts.ID, true); var oField = (SPFieldLookup)oResourcePool.Fields.GetFieldByInternalName("Department"); oField.LookupField = "DisplayName"; oField.Update(); } else { LogMessage("\t", "Departments list missing", 3); } } else { SPField oDeptField = oResourcePool.Fields.GetFieldByInternalName("Department"); if (oDeptField.Type != SPFieldType.Lookup) { LogMessage("\tReplacing Department field"); SPList oDepts = oResourcePool.ParentWeb.Lists.TryGetList("Departments"); if (oDepts != null) { if (oDeptField.Sealed) { LogMessage("\t\tUnsealing the field"); oDeptField.Sealed = false; try { oDeptField.Update(); } catch { Thread.Sleep(1000); oDeptField.Update(); } } LogMessage("\t\tAllowing deletion of the field"); oDeptField.AllowDeletion = true; try { oDeptField.Update(); } catch { Thread.Sleep(1000); oDeptField.Update(); } LogMessage("\t\tDeleting the field"); try { oDeptField.Delete(); } catch { Thread.Sleep(1000); oDeptField.Delete(); } LogMessage("\t\tAdding the Department lookup"); oResourcePool.Fields.AddLookup("Department", oDepts.ID, true); Thread.Sleep(1000); LogMessage("\t\tConfiguring the Department lookup"); var oField = (SPFieldLookup)oResourcePool.Fields.GetFieldByInternalName("Department"); oField.LookupField = "DisplayName"; try { oField.Update(); } catch { Thread.Sleep(1000); oField.Update(); } LogMessage("", "The Department field is replaced", 1); } else { LogMessage("\t", "Departments list missing", 3); } } } } catch (Exception ex) { LogMessage("\t", "Adding Department field: " + ex.Message, 3); } oResourcePool.Update(); }
public void Teardown(ref SPWeb web) { var types = Entities; //provision lists foreach (var iListDefinition in types) { try { SPList list = web.Lists[iListDefinition.ListName]; list.Delete(); web.Update(); } catch { } try { SPContentType cType = web.ContentTypes[iListDefinition.Name]; if (cType != null) { cType.Delete(); web.Update(); } } catch { } try { SPContentType cType = web.ContentTypes[iListDefinition.ContentTypeId]; if (cType != null) { cType.Delete(); web.Update(); } } catch { } foreach (var iColumn in iListDefinition.Columns) { try { SPField field = web.Fields[iColumn.DisplayName]; field.Delete(); } catch { } } web.Update(); } List <SPField> deletables = new List <SPField>(); foreach (SPField iField in web.Fields) { if (iField.Group == GroupName) { deletables.Add(iField); } } foreach (var iField in deletables) { try { iField.Delete(); } catch { } } web.Update(); }