public static List <SPField> FindAllFieldOfType(this SPWeb web, SPFieldType type) { return(web.AvailableFields.Cast <SPField>() .Where <SPField>(ct => ct.Type == type) .OrderBy(ct => ct.Title) .ToList <SPField>()); }
/// <summary> /// Create one column site of Taxonomy /// </summary> /// <param name="args"></param> private static bool CreateColumnSiteTaxonomy(ParamsCreateSite args, SPFieldType type) { var result = false; var columnSite = new SiteColumn(new ParamsSiteColumnDefaultValue { Web = args.Web, Name = args.Name, FieldType = type, Requiered = args.Requiered, Group = args.Group, AddPrefix = args.AddPrefix, DefaultValue = args.DefaultValue }); if (!columnSite.Exist()) { result = columnSite.CreateTaxonomy(args.GroupTerm, args.Term, args.MultiValue, args.Requiered); } args.Name = (args.AddPrefix) ? string.Concat(Constants.Prefix, args.Name) : args.Name; columnSite.RenameField(args.Name, string.IsNullOrEmpty(args.DisplayName) ? args.Name : args.DisplayName); if (args.Hidden) { columnSite.Hidden(); } return result; }
/// <summary> /// Adds the field to list. Only adds the field if it doesn't already exist. /// </summary> /// <param name="fieldName">Name of the field.</param> /// <param name="fieldType">Type of the field.</param> /// <param name="isRequired">if set to <c>true</c> [is required].</param> /// <returns></returns> protected string AddFieldToList(string fieldName, SPFieldType fieldType, bool isRequired) { string field = string.Empty; SPList list = null; ForumApplication.Instance.SpWeb.AllowUnsafeUpdates = true; try { if (ListExists) { list = ForumApplication.Instance.SpWeb.Lists[listName]; field = list.Fields[fieldName].ToString(); } } catch { try { field = list.Fields.Add(fieldName, fieldType, isRequired); } catch (Exception) { } } return(field); }
public static TF AddField <TF>( this SPFieldCollection fields, Guid fieldId, SPFieldType fieldType, string displayName, string name, bool required, Action <TF> action) where TF : SPField { //name = SPHelper.ConvertHebrewToUnicodeHex(name); if (!fields.Contains(fieldId)) { string fieldXml = string.Format( @"<Field ID=""{0}"" Name=""{1}"" StaticName=""{1}"" DisplayName=""{2}"" Type=""{3}"" Overwrite=""TRUE"" SourceID=""http://schemas.microsoft.com/sharepoint/v3"" />", fieldId, name, displayName, fieldType); name = fields.AddFieldAsXml(fieldXml); } //TF field = (TF)fields.GetFieldByInternalName(name); TF field = (TF)fields.GetField(name); field.Required = required; if (action != null) { action(field); } field.Update(); return(field); }
private static bool TryAddField(SPList list, string InternalName, SPFieldType type, string Title, bool Hidden) { SPField field = null; try { field = list.Fields.GetFieldByInternalName(InternalName); } catch { } if (field == null) { try { string sField = list.Fields.Add(InternalName, type, false); field = list.Fields.GetFieldByInternalName(InternalName); field.Title = Title; field.Hidden = Hidden; field.Update(); return(true); } catch { return(false); } } else { return(true); } }
/// <summary> /// Adds the field to list. Only adds the field if it doesn't already exist. /// </summary> /// <param name="fieldName">Name of the field.</param> /// <param name="fieldType">Type of the field.</param> /// <param name="isRequired">if set to <c>true</c> [is required].</param> /// <returns></returns> protected string AddFieldToList(string fieldName, SPFieldType fieldType, bool isRequired) { string field = string.Empty; SPList list = null; ForumApplication.Instance.SpWeb.AllowUnsafeUpdates = true; try { if (ListExists) { list = ForumApplication.Instance.SpWeb.Lists[listName]; field = list.Fields[fieldName].ToString(); } } catch { try { field = list.Fields.Add(fieldName, fieldType, isRequired); } catch (Exception) { } } return field; }
private void TestAddItemWithDataRow(SPFieldType fieldType) { // Arrange var arrGTemp = new SortedList(); var dataSet = new DataSet(); dataSet.Tables.Add(new DataTable()); dataSet.Tables.Add(new DataTable()); dataSet.Tables.Add(new DataTable()); dataSet.Tables.Add(new DataTable()); SetupShimsForSqlClient(); SetupShimsForHttpRequest(); PrivateObject.SetField("dsTSMeta", dataSet); PrivateObject.SetField("arrGroupFields", new[] { DummyString }); PrivateObject.SetField("list", new ShimSPList().Instance); ShimDataTable.AllInstances.SelectString = (_, __) => new DataRow[] { new ShimDataRow() }; ShimDataRow.AllInstances.ItemGetInt32 = (_, __) => DummyString; ShimDataRow.AllInstances.ItemGetString = (_, str) => DummyString; ShimSPField.AllInstances.TypeGet = _ => fieldType; ShimSPViewFieldCollection.AllInstances.CountGet = _ => DummyInt; // Act PrivateObject.Invoke("addItem", new ShimDataRow().Instance, arrGTemp, new ShimSPWeb().Instance); // Assert arrGTemp.ShouldSatisfyAllConditions( () => arrGTemp.Count.ShouldBe(1), () => { var keys = arrGTemp.Keys.Cast <string>().ToList(); keys.ShouldNotBeNull(); keys.Count.ShouldBeGreaterThan(0); keys[0].ShouldContain(DummyString); }); }
public static TF AddField <TF>( this SPFieldCollection fields, SPFieldType fieldType, string internalName, string displayName, string groupName, bool required, Action <TF> action) where TF : SPField { return(fields.AddField <TF>(fieldType, internalName, required, field => { field.Title = displayName; if (!string.IsNullOrEmpty(groupName)) { field.Group = groupName; } if (action != null) { action(field); } })); }
private static SPField CreateSpField(string displayName, SPFieldType fieldType, int fieldNumber, SPField spFieldBase = null) { var requiredField = false; var hiddenField = false; var defaultValueField = default(string); var showInEditFormField = default(bool?); var showInNewForm = default(bool?); var spFieldTypeField = fieldType; var shimSpField = spFieldBase == null ? new ShimSPField() : new ShimSPField(spFieldBase); shimSpField.TypeDisplayNameGet = () => displayName; shimSpField.InternalNameGet = () => $"Int{fieldNumber}"; shimSpField.RequiredGet = () => requiredField; shimSpField.RequiredSetBoolean = arg => requiredField = arg; shimSpField.HiddenGet = () => hiddenField; shimSpField.HiddenSetBoolean = arg => hiddenField = arg; shimSpField.TypeGet = () => spFieldTypeField; shimSpField.TypeSetSPFieldType = arg => spFieldTypeField = arg; shimSpField.DefaultValueGet = () => defaultValueField; shimSpField.DefaultValueSetString = arg => defaultValueField = arg; shimSpField.ShowInEditFormGet = () => showInEditFormField; shimSpField.ShowInEditFormSetNullableOfBoolean = arg => showInEditFormField = arg; shimSpField.ShowInNewFormGet = () => showInNewForm; shimSpField.ShowInNewFormSetNullableOfBoolean = arg => showInNewForm = arg; var spField = shimSpField.Instance; return(spField); }
public static SPField EnsureField(this SPList list, SPFieldType type, string displayName, string internalName, bool isRequired, SPCalendarType calendarType) { var field = list.EnsureField(type, displayName, internalName, isRequired); if (field.Type == SPFieldType.DateTime) { try { if (!list.Fields.ContainsField(internalName)) { list.Fields.Add(internalName, SPFieldType.DateTime, false); list.Update(); (field as SPFieldDateTime).DisplayFormat = SPDateTimeFieldFormatType.DateOnly; (field as SPFieldDateTime).CalendarType = calendarType; field.Update(); } else { (field as SPFieldDateTime).DisplayFormat = SPDateTimeFieldFormatType.DateOnly; (field as SPFieldDateTime).CalendarType = calendarType; field.Update(); } } catch (Exception ex) { Log.Error(ex); } } return(field); }
public FieldDefinition <TParentDefinition> WithChoices(params string[] choiceOptions) { type = SPFieldType.Choice; choices = new StringCollection(); choices.AddRange(choiceOptions); return(this); }
public FieldDefinition <TParentDefinition> AsLookupTo(SPList specificTargetList, string specificTargetFieldName) { type = SPFieldType.Lookup; targetList = specificTargetList; targetFieldName = specificTargetFieldName; return(this); }
/// <summary> /// Initializes a new instance of the <see cref="CamlQueryComparisonOperator"/> class. /// </summary> /// <param name="fieldName">Name of the field.</param> /// <param name="fieldType">Type of the field.</param> /// <param name="fieldValue">The field value.</param> /// <param name="elementType">Type of the element.</param> public CamlQueryComparisonOperator(string fieldName, SPFieldType fieldType, string fieldValue, CamlQuerySchemaElements elementType) { FieldName = fieldName; FieldType = fieldType; FieldValue = fieldValue; _elementType = elementType; }
public static TF AddField <TF>( this SPFieldCollection fields, SPFieldType fieldType, string name, bool required, Action <TF> action) where TF : SPField { //name = SPHelper.ConvertHebrewToUnicodeHex(name); if (!fields.ContainsField(name)) { name = AddField(fields, fieldType, name, required, false); } //TF field = (TF)fields.GetFieldByInternalName(name); TF field = (TF)fields.GetField(name); if (action != null) { action(field); } field.Update(); return(field); }
protected MultipleValueOperator(string operatorName, IEnumerable <T> values, SPFieldType type) : base(operatorName) { if (values != null) { Values = values.Select(val => new Value <T>(val, type)); } }
internal static string SQLDataType(this SPFieldType type) { if (m_ConveribleTypes.ContainsKey(type)) { return(m_ConveribleTypes[type]); } return(String.Empty); }
private object ConvertValueForFieldType(SPFieldType fieldType, string stringValue) { switch (fieldType) { case SPFieldType.DateTime: return(DateTime.Parse(stringValue)); case SPFieldType.Counter: case SPFieldType.Integer: case SPFieldType.Lookup: return(int.Parse(stringValue)); case SPFieldType.Number: return(double.Parse(stringValue)); case SPFieldType.User: var user = new ShimSPUser() { IDGet = () => int.Parse(stringValue), LoginNameGet = () => stringValue }; return(user.Instance); case SPFieldType.AllDayEvent: case SPFieldType.Attachments: case SPFieldType.Boolean: case SPFieldType.Calculated: case SPFieldType.Choice: case SPFieldType.Computed: case SPFieldType.ContentTypeId: case SPFieldType.CrossProjectLink: case SPFieldType.Currency: case SPFieldType.Error: case SPFieldType.File: case SPFieldType.Geolocation: case SPFieldType.GridChoice: case SPFieldType.Guid: case SPFieldType.Invalid: case SPFieldType.MaxItems: case SPFieldType.ModStat: case SPFieldType.MultiChoice: case SPFieldType.Note: case SPFieldType.OutcomeChoice: case SPFieldType.PageSeparator: case SPFieldType.Recurrence: case SPFieldType.Text: case SPFieldType.ThreadIndex: case SPFieldType.Threading: case SPFieldType.URL: case SPFieldType.WorkflowEventType: case SPFieldType.WorkflowStatus: break; } return(stringValue); }
public SiteColumnToCreate(string internalName, string displayName, SPFieldType fieldType, string group, StringCollection choices, string defaultValue, string description) { this.InternalName = internalName; this.DisplayName = displayName; this.FieldType = fieldType; this.Group = group; this.Choices = choices; this.DefaultValue = defaultValue; this.Description = description; }
public ColumnDef(string sqlColumnName, string internalName, string displayName, SPFieldType spFieldType, SqlDbType sqlDbType, int size) { _sqlColumnName = sqlColumnName; ColumnType = spFieldType; _internalName = internalName; _displayName = displayName; _sqlColumnType = sqlDbType; _sqlColumnSize = size; }
public ColumnDetails(Guid columnId, string columnInternalName, string columnDisplayName, string columnDescription, SPFieldType columnType, string columnChoices, string columnTypeAsString, string columnGroup) { Id = columnId; InternalName = columnInternalName; DisplayName = columnDisplayName; Description = columnDescription; ColumnChoices = columnChoices; Type = columnType; TypeAsString = columnTypeAsString; Group = columnGroup; }
private ShimSPField GetDefaultSPField(string colname, SPFieldType type, bool required) { return(new ShimSPField { ColNameGet = () => colname, TypeGet = () => type, RequiredGet = () => required, Update = () => { _fieldUpdated = true; }, InternalNameGet = () => colname }); }
private ShimSPField GetShimSPField(string fieldName, SPFieldType fieldType = SPFieldType.Choice) { return(new ShimSPField() { IdGet = () => DummyGuid, TitleGet = () => fieldName, TypeGet = () => fieldType, Update = () => _updatedFields.Add(fieldName), Delete = () => _deletedFields.Add(fieldName), }); }
private void initControl() { try { SPSecurity.RunWithElevatedPrivileges(delegate() { string listName = webObj.ListName; string[] listfields = webObj.ListFields.Split(';'); string siteUrl = webObj.SiteUrl; using (SPSite spSite = new SPSite(siteUrl)) //找到网站集 { using (SPWeb spWeb = spSite.OpenWeb()) { SPList splist = spWeb.Lists.TryGetList(listName); for (int i = 0; i < listfields.Length; i++) { TableRow tr = new TableRow(); SPField fd = splist.Fields[listfields[i]]; string fdInternalName = fd.InternalName; //创建标签列 TableCell tc1 = new TableCell();//标签 Label lb = new Label(); lb.ID = fdInternalName; lb.Text = listfields[i]; tc1.Controls.Add(lb); tr.Cells.Add(tc1); //创建表单列 SPFieldType fdtype = fd.Type; TableCell tc2 = CreatFormCell(fdtype, fdInternalName, listfields[i]);//表单 tr.Cells.Add(tc2); //创建说明列 TableCell tc3 = new TableCell();//说明 Label lbDesc = new Label(); lbDesc.ID = fdInternalName + "Desc"; lbDesc.Text = fd.Description; tc1.Controls.Add(lbDesc); tr.Cells.Add(tc3); tbForms.Rows.Add(tr); } } } }); } catch (Exception ex) { lberr.Text = ex.ToString(); } }
private SPFieldType parseFieldType(string s) { SPFieldType fieldType = SPFieldType.Invalid; foreach (SPFieldType t in Enum.GetValues(typeof(SPFieldType))) { if (t.ToString() == s) { fieldType = t; } } return(fieldType); }
public static SPField EnsureField(this SPList list, SPFieldType type, string displayName, string internalName, bool isRequired, string formula) { var field = list.EnsureField(type, displayName, internalName, isRequired); if (field.Type == SPFieldType.Calculated) { var strNewField = (SPFieldCalculated)field; strNewField.Formula = formula; strNewField.Update(); } return(field); }
public void GetSpFieldTypeTest() { string fieldName = string.Empty; // TODO: Initialize to an appropriate value string fieldValue = string.Empty; // TODO: Initialize to an appropriate value string fieldType = string.Empty; // TODO: Initialize to an appropriate value XmlLookupNode target = new XmlLookupNode(fieldName, fieldValue, fieldType); // TODO: Initialize to an appropriate value SPFieldType expected = new SPFieldType(); // TODO: Initialize to an appropriate value SPFieldType actual; actual = target.GetSpFieldType(); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public static SPField CreateSiteColumn(SPWeb web, string displayName, SPFieldType fieldType, string groupDescriptor) { if (!web.Fields.ContainsField(displayName)) { string fieldName = web.Fields.Add(displayName, fieldType, false); SPField field = web.Fields.GetFieldByInternalName(fieldName); field.Group = groupDescriptor; field.Update(); return(field); } return(web.Fields[displayName]); }
public SiteColumnCustom(string name, SPFieldType columnType, string group, string[] choices = null, bool dateOnly = false) { Name = name; ColumnType = columnType; Group = group; DateOnly = dateOnly; if (choices != null) { StringCollection choiceCollection = new StringCollection(); choiceCollection.AddRange(choices); Choices = choiceCollection; } }
private string GetFieldRef(KeyValuePair <string, string> field, SPFieldType fieldType) { StringBuilder sb = new StringBuilder(); sb.Append("<Eq>"); sb.Append("<FieldRef Name='"); sb.Append(field.Key); sb.Append(fieldType == SPFieldType.Lookup ? "' LookupId='TRUE' />" : "' />"); sb.Append(fieldType == SPFieldType.Lookup ? "<Value Type='Lookup'>" : "<Value Type='Text'>"); sb.Append(field.Value); sb.Append("</Value>"); sb.Append("</Eq>"); return(sb.ToString()); }
public static Type GetValueType(SPFieldType type, bool allowMultipleValues = false) { if (type == SPFieldType.Guid) { return(typeof(Guid)); } if (type == SPFieldType.Text || type == SPFieldType.Note || type == SPFieldType.Choice) { return(typeof(string)); } if (type == SPFieldType.Number || type == SPFieldType.Currency) { return(typeof(double)); } if (type == SPFieldType.MultiChoice) { return(typeof(SPFieldMultiChoiceValue)); } if (type == SPFieldType.Boolean || type == SPFieldType.Recurrence || type == SPFieldType.Attachments || type == SPFieldType.AllDayEvent || type == SPFieldType.CrossProjectLink) { return(typeof(bool)); } if (type == SPFieldType.Lookup) { return(allowMultipleValues ? typeof(SPFieldLookupValueCollection) : typeof(SPFieldLookupValue)); } if (type == SPFieldType.User) { return(allowMultipleValues ? typeof(SPFieldUserValueCollection) : typeof(SPFieldUserValue)); } if (type == SPFieldType.URL) { return(typeof(SPFieldUrlValue)); } if (type == SPFieldType.DateTime) { return(typeof(DateTime)); } if (type == SPFieldType.Integer || type == SPFieldType.Counter || type == SPFieldType.ModStat || type == SPFieldType.WorkflowStatus) { return(typeof(int)); } if (type == SPFieldType.ContentTypeId) { return(typeof(SPContentTypeId)); } return(null); }
public static void InsertFormulaFieldToList(string fieldName, string displayName, SPList list, string formula, SPFieldType type, SPNumberFormatTypes format) { if (list.Fields.ContainsField(fieldName)) { list.Fields.Delete(fieldName); } string temp = list.Fields.Add(displayName, SPFieldType.Calculated, false); SPFieldCalculated f = (SPFieldCalculated)list.Fields[temp]; f.Formula = formula; f.OutputType = type; f.DisplayFormat = format; f.Update(); list.Update(); }
public static string AddField( this SPFieldCollection fields, SPFieldType fieldType, string name, bool required, bool overwrite) { if (overwrite && fields.ContainsField(name)) { fields.Delete(name); } name = fields.Add(name, fieldType, required); return(name); }
/// <summary> /// Creates a new site column in the specified web (teamUrl /// </summary> /// <param name="teamUrl">The SiteCollection</param> /// <param name="displayName">Display name of the column</param> /// <param name="fieldType">Field type of the column</param> /// <param name="groupDescriptor">Group name for the column</param> /// <returns></returns> internal SPField CreateSiteColumn(string teamUrl, string displayName, SPFieldType fieldType, string groupDescriptor) { using (SPWeb spWeb = GetTeamWeb(teamUrl)) { SPField field = this.GetSiteColumn(teamUrl, displayName); if (field != null) { string fieldName = spWeb.Fields.Add(displayName, fieldType, false); field = spWeb.Fields.GetFieldByInternalName(fieldName); field.Group = groupDescriptor; field.Update(); } return(field); } }
public static CAMLFilter In(Guid fieldId, IList <object> values, SPFieldType camlType) { if (!values.Any()) { throw new ArgumentException("values"); } var filter = new CAMLFilter(); var valuesCaml = values.Select(x => string.Format("<Value Type='{0}'>{1}</Value>", camlType, x)); filter.FilterExpression = string.Format(CultureInfo.InvariantCulture, "<{0}><FieldRef ID='{1}' {2}/><Values>{3}</Values></{0}>", Operator.In, fieldId, camlType == SPFieldType.User || camlType == SPFieldType.Lookup ? "LookupId='TRUE'" : "", string.Join("", valuesCaml)); return(filter); }
public static List<Operators> GetOperators(SPFieldType fieldType) { switch (fieldType) { case SPFieldType.Computed: case SPFieldType.Note: case SPFieldType.Text: case SPFieldType.File: return new List<Operators>(){ Operators.Equal, Operators.NotEqual, Operators.Contains, Operators.StartsWith }; case SPFieldType.Lookup: case SPFieldType.User: return new List<Operators>(){ Operators.Equal, Operators.NotEqual, Operators.Contains, }; case SPFieldType.MultiChoice: return new List<Operators>(){ Operators.NotEqual, Operators.Contains, }; case SPFieldType.Currency: case SPFieldType.Integer: case SPFieldType.Number: return new List<Operators>(){ Operators.Equal, Operators.NotEqual, Operators.GreaterThan, Operators.LessThan }; case SPFieldType.DateTime: return new List<Operators>(){ Operators.Equal, Operators.NotEqual, Operators.EarlierThan, Operators.LaterThan }; } return new List<Operators>() { Operators.Equal, Operators.NotEqual }; }
public void AddColumn(SPList list, string fieldname, SPFieldType type, bool required) { if (String.IsNullOrEmpty(fieldname)) throw new ArgumentException("\tAddColumn unsuccessful: fieldname cannot be null"); if (list == null) throw new ArgumentException(String.Format("\tAddColumn {0} unsuccessful: List cannot be null", fieldname)); else { if (!list.Fields.ContainsField(fieldname)) { list.Fields.Add(fieldname, type, required); SPEvolutionLog.Instance.Write(String.Format("\tAddColumn {0} successful", fieldname)); } else SPEvolutionLog.Instance.Write(String.Format("\tAddColumn {0} unsuccessful: Column with this name already exist", fieldname), SPEvolutionLogLevel.ValidationError); } }
/// <summary> /// Determines whether field can be used in query. /// </summary> /// <param name="fieldType">Type of the field.</param> /// <param name="fieldName">Name of the field.</param> /// <returns> /// <c>True</c> if is valid; otherwise, <c>false</c>. /// </returns> public static bool IsValidFieldForQuery(SPFieldType fieldType, string fieldName) { return !(fieldType == SPFieldType.Computed && fieldName == SPBuiltInFieldNames.Edit) && !(fieldType == SPFieldType.Lookup && fieldName == SPBuiltInFieldNames.FolderChildCount); }
private void ModifyField(SPList articles, string internalName, string newDisplayName, bool? isRequired, string defaultValue, SPFieldType fieldType, bool? richText, SPRichTextMode richTextMode) { if (articles.Fields.ContainsField(internalName)) { SPField field = articles.Fields.GetFieldByInternalName(internalName); if (!string.IsNullOrEmpty(newDisplayName)) field.Title = newDisplayName; if (isRequired.HasValue) field.Required = isRequired.Value; if (!string.IsNullOrEmpty(defaultValue)) field.DefaultValue = defaultValue; if (fieldType != SPFieldType.Invalid) field.Type = fieldType; if (richText.HasValue) { (field as SPFieldMultiLineText).RichText = richText.Value; (field as SPFieldMultiLineText).RichTextMode = richTextMode; } field.Update(); } }
public CamlFieldExpression(string name, SPFieldType type) { Name = name; FieldType = type; }
/// <summary> /// Initializes a new instance of the <see cref="Neq"/> class. /// </summary> /// <param name="fieldName">Name of the field.</param> /// <param name="fieldType">Type of the field.</param> /// <param name="fieldValue">The field value.</param> public Neq(string fieldName, SPFieldType fieldType, string fieldValue) : base(fieldName, fieldType, fieldValue, CamlQuerySchemaElements.Neq) { }
protected void EnsureField(SPList list, string fieldName, SPFieldType fieldType, SPView view) { if (!list.Fields.ContainsField(fieldName)) { string filedName = list.Fields.Add(fieldName, fieldType, false); view.ViewFields.Add(filedName); } }
public CAML AddLessThanOrEqualTo(Guid fieldId, SPFieldType fieldType, object value) { return AddPredicate(Predicates.Leq, fieldId, fieldType, value); }
/// <summary> /// Checks if a site column exists in a site and creates it if it doesn't exist. /// </summary> /// <param name="site">The site to check.</param> /// <param name="columnId">The GUID of the column to use if it needs to be created.</param> /// <param name="columnInternalName">The internal name of the column to check.</param> /// <param name="columnDisplayName">The display name of the column to use if it needs to be created.</param> /// <param name="columnDescription">The description of the column to use if it needs to be created.</param> /// <param name="columnType">The type of the column</param> /// <param name="columnChoices">If the type of the column is choice this is the xml to put in the choices</param> /// <param name="columnGroup">The column group to add the site column to if it needs to be created.</param> /// <param name="columnXml">The XML definition of the site column.</param> /// <param name="isNewColumn">A boolean that is set to true, if a new column is created; otherwise, it is set to false.</param> /// <returns>A SPField object that references an existing or newly created site column.</returns> public static SPField EnsureSiteColumn(this SPWeb site, Guid columnId, string columnInternalName, string columnDisplayName, string columnDescription, SPFieldType columnType, string columnChoices, string columnTypeAsString, string columnGroup, ref bool isNewColumn) { ColumnDetails columnDetail = new ColumnDetails(columnId, columnInternalName, columnDisplayName, columnDescription, columnType, columnChoices, columnTypeAsString, columnGroup); return EnsureSiteColumn(site, columnDetail, ref isNewColumn); }
/// <summary> /// Initializes a new instance of the <see cref="Contains"/> class. /// </summary> /// <param name="fieldName">Name of the field.</param> /// <param name="fieldType">Type of the field.</param> /// <param name="fieldValue">The field value.</param> public Contains(string fieldName, SPFieldType fieldType, string fieldValue) : base(fieldName, fieldType, fieldValue, CamlQuerySchemaElements.Contains) { }
public static bool IsFieldTypeRangeCapable(SPFieldType fieldTypeToCheck) { if (SPFieldType.DateTime != fieldTypeToCheck && SPFieldType.Number != fieldTypeToCheck && SPFieldType.Currency != fieldTypeToCheck) return SPFieldType.Integer == fieldTypeToCheck; return true; }
/// <summary> /// Tries the parse value. /// </summary> /// <param name="fieldType">Type of the field.</param> /// <param name="searchText">The search text.</param> /// <returns>True if parse successful, otherwise False.</returns> public static bool TryParseValue(SPFieldType fieldType, ref string searchText) { bool isParsedSuccessfully = false; switch (fieldType) { case SPFieldType.Boolean: BoolenValues boolenValue; isParsedSuccessfully = EnumHelper.TryParse(searchText, out boolenValue); if (isParsedSuccessfully) searchText = ((int)boolenValue).ToString(); return isParsedSuccessfully; case SPFieldType.WorkflowEventType: case SPFieldType.Counter: case SPFieldType.Integer: int intValue; return int.TryParse(searchText, out intValue); case SPFieldType.Number: case SPFieldType.Currency: double doubleValue; isParsedSuccessfully = double.TryParse(searchText, out doubleValue); if (isParsedSuccessfully) searchText = doubleValue.ToString().Replace(',', '.'); return isParsedSuccessfully; case SPFieldType.DateTime: DateTime dateValue; isParsedSuccessfully = DateTime.TryParse(searchText, out dateValue); if (isParsedSuccessfully) searchText = SPUtility.CreateISO8601DateTimeFromSystemDateTime(dateValue); return isParsedSuccessfully; case SPFieldType.ContentTypeId: case SPFieldType.AllDayEvent: case SPFieldType.Attachments: case SPFieldType.CrossProjectLink: case SPFieldType.PageSeparator: case SPFieldType.Error: case SPFieldType.File: case SPFieldType.GridChoice: case SPFieldType.Invalid: case SPFieldType.ThreadIndex: case SPFieldType.Threading: case SPFieldType.MaxItems: case SPFieldType.Recurrence: return false; case SPFieldType.ModStat: case SPFieldType.MultiChoice: case SPFieldType.Calculated: case SPFieldType.Choice: case SPFieldType.WorkflowStatus: case SPFieldType.Guid: case SPFieldType.URL: case SPFieldType.Text: case SPFieldType.Note: case SPFieldType.Lookup: case SPFieldType.User: case SPFieldType.Computed: return true; } return true; }
public ColumnDetails(Guid columnId, string columnInternalName, string columnDisplayName, string columnDescription, SPFieldType columnType, string columnGroup) : this(columnId, columnInternalName, columnDisplayName, columnDescription, columnType, string.Empty, string.Empty, columnGroup) { }
/// <summary> /// Checks if a column exists in a list and creates it if it doesn't exist. /// </summary> /// <param name="list">The site to check.</param> /// <param name="columnId">The GUID of the column to use if it needs to be created.</param> /// <param name="columnInternalName">The internal name of the column to check.</param> /// <param name="columnDisplayName">The display name of the column to use if it needs to be created.</param> /// <param name="columnDescription">The description of the column to use if it needs to be created.</param> /// <param name="columnGroup">The column group to add the site column to if it needs to be created.</param> /// <param name="columnXml">The XML definition of the site column.</param> /// <param name="isNewColumn">A boolean that is set to true, if a new column is created; otherwise, it is set to false.</param> /// <returns>A SPField object that references an existing or newly created site column.</returns> public static SPField EnsureColumn(this SPList list, Guid columnId, string columnInternalName, string columnDisplayName, string columnDescription, SPFieldType columnType, string columnTypeAsString, string columnGroup, bool isSiteColumn, ref bool isNewColumn) { ColumnDetails columnDetail = new ColumnDetails(columnId, columnInternalName, columnDisplayName, columnDescription, columnType, string.Empty, columnTypeAsString, columnGroup); return EnsureColumn(list, columnDetail, isSiteColumn, ref isNewColumn); }
private CAML Result(SPFieldType fieldType) { return _camlBuilder .AddPredicate(_predicate, _fieldId, fieldType, _value); }
public CAML AddGreaterThan(Guid fieldId, SPFieldType fieldType, object value) { return AddPredicate(Predicates.Gt, fieldId, fieldType, value); }
protected BaseFieldCreator(string internalName, string displayName, SPFieldType type) { this.Name = displayName; this.InternalName = internalName; this.Type = type; }
/// <summary> /// Gets the CAML template required to create a column. /// </summary> /// <param name="columnType">An SPFieldType object that specifies the type of column.</param> /// <param name="columnTypeAsString">A string specifying the type of column for special column types e.g. Publishing HTML column.</param> /// <returns></returns> public string GetXmlTemplate(SPFieldType columnType, string columnTypeAsString) { string xmlTemplate = string.Empty; switch (columnType) { case SPFieldType.Text: xmlTemplate = _textColumnXml; break; case SPFieldType.Number: xmlTemplate = _numberColumnXml; break; case SPFieldType.Integer: xmlTemplate = _intColumnXml; break; case SPFieldType.Note: xmlTemplate = _multiLineColumnXml; break; case SPFieldType.DateTime: xmlTemplate = _dateColumnXml; break; case SPFieldType.URL: xmlTemplate = _hyperlinkColumnXml; break; case SPFieldType.User: xmlTemplate = _personColumnXml; break; case SPFieldType.Boolean: xmlTemplate = _booleanXmlTemplate; break; case SPFieldType.Choice: xmlTemplate = _choiceColumnXml; break; case SPFieldType.Lookup: xmlTemplate = _lookupColumnXml; break; case SPFieldType.Invalid: switch (columnTypeAsString.ToLower()) { case "html": xmlTemplate = _htmlXmlTemplate; break; case "taxonomyfieldtype": xmlTemplate = _taxonomyColumnXml; break; default: throw new ApplicationException("The specified type is not supported."); } break; default: throw new ApplicationException("The specified type is not supported."); } return xmlTemplate; }
public CAML AddEqual(Guid fieldId, SPFieldType fieldType, object value) { return AddPredicate(Predicates.Eq, fieldId, fieldType, value); }
public static SPField GetSiteColumn(SPWeb web, string displayName, SPFieldType fieldType, string groupDescriptor) { SPSite spSite = new SPSite(web.Url); SPWeb spWeb = spSite.RootWeb; if (!spWeb.Fields.ContainsField(displayName)) { string fieldName = spWeb.Fields.Add(displayName, fieldType, false); SPField field = spWeb.Fields.GetFieldByInternalName(fieldName); field.Group = groupDescriptor; field.Update(); return field; } return spWeb.Fields[displayName]; }
public CAML AddPredicate(Predicates predicate, Guid fieldId, SPFieldType fieldType, object value) { string filterExpression = string.Format(CultureInfo.InvariantCulture, "<{0}><FieldRef ID='{1}'/><Value Type='{2}'>{3}</Value></{0}>" , predicate, fieldId, fieldType, FormatValue(value)); AddFilter(new CAMLFilter { FilterExpression = filterExpression }); return this; }
public static SPField CreateSiteColumn(SPWeb web, string fieldName, SPFieldType spFieldType, bool required) { // Validation web.RequireNotNull("web"); fieldName.RequireNotNullOrEmpty("fieldName"); if (web.AvailableFields.ContainsField(fieldName)) { return web.AvailableFields[fieldName]; } string internalName = web.Fields.Add(fieldName, spFieldType, required); return web.Fields.GetFieldByInternalName(internalName); }
private object ConvertValueForFieldType(SPFieldType fieldType, string stringValue) { switch (fieldType) { case SPFieldType.DateTime: return DateTime.Parse(stringValue); case SPFieldType.Counter: case SPFieldType.Integer: case SPFieldType.Lookup: return int.Parse(stringValue); case SPFieldType.Number: return double.Parse(stringValue); case SPFieldType.User: var user = new ShimSPUser() { IDGet = () => int.Parse(stringValue), LoginNameGet = () => stringValue }; return user.Instance; case SPFieldType.AllDayEvent: case SPFieldType.Attachments: case SPFieldType.Boolean: case SPFieldType.Calculated: case SPFieldType.Choice: case SPFieldType.Computed: case SPFieldType.ContentTypeId: case SPFieldType.CrossProjectLink: case SPFieldType.Currency: case SPFieldType.Error: case SPFieldType.File: case SPFieldType.Geolocation: case SPFieldType.GridChoice: case SPFieldType.Guid: case SPFieldType.Invalid: case SPFieldType.MaxItems: case SPFieldType.ModStat: case SPFieldType.MultiChoice: case SPFieldType.Note: case SPFieldType.OutcomeChoice: case SPFieldType.PageSeparator: case SPFieldType.Recurrence: case SPFieldType.Text: case SPFieldType.ThreadIndex: case SPFieldType.Threading: case SPFieldType.URL: case SPFieldType.WorkflowEventType: case SPFieldType.WorkflowStatus: break; } return stringValue; }