private void FieldExistsSoWeCanUpgrade( SPList list, int parentMessageId, string internalName, XmlNode internalFieldXml, string typeValue, bool overwrite, SPField spField) { if (spField == null) { throw new ArgumentNullException(nameof(spField)); } if (spField.TypeAsString.Equals(typeValue, StringComparison.InvariantCultureIgnoreCase)) { if (overwrite) { if (bVerifyOnly) { addMessage(ErrorLevels.Upgrade, internalName, "Field exists and will overwrite", parentMessageId); } else { try { ApplicationInstallerHelpers.InstallListFieldSwapXml(list, spField, internalFieldXml); addMessage(ErrorLevels.NoError, internalName, "Field updated", parentMessageId); } catch (Exception ex) { addMessage(ErrorLevels.Error, internalName, "Error updating field schema: " + ex.Message, parentMessageId); Trace.WriteLine(ex.ToString()); } } } else { addMessage(ErrorLevels.Warning, internalName, "Field exists and cannot overwrite", parentMessageId); } } else { addMessage(ErrorLevels.Error, internalName, "Field type mistmatch", parentMessageId); } }
private void FieldNewLetsAdd( SPList list, int parentMessageId, string internalName, XmlNode internalFieldXml, string typeValue) { if (bVerifyOnly) { ApplicationInstallerHelpers.GetFieldTypeByString(typeValue); addMessage(ErrorLevels.NoError, internalName, string.Empty, parentMessageId); } else { try { var spField = ApplicationInstallerHelpers.InstallListFieldsAddField(list, internalName, typeValue, internalFieldXml); try { if (spField != null) { ApplicationInstallerHelpers.InstallListFieldSwapXml(list, spField, internalFieldXml); } addMessage(ErrorLevels.NoError, internalName, string.Empty, parentMessageId); } catch (Exception ex) { addMessage(ErrorLevels.Error, internalName, "Error updating field schema: " + ex.Message, parentMessageId); Trace.WriteLine(ex.ToString()); } } catch (Exception ex) { addMessage(ErrorLevels.Error, internalName, "Error adding field: " + ex.Message, parentMessageId); Trace.WriteLine(ex.ToString()); } } }