private void SetProperty(int type, object value) { Property current = _firstProperty; Property previous = null; while (current != null && current.GetType() != type) { previous = current; current = current._next; } if (current != null) { current._value = value; } else { switch (type) { case Property.COMMENT: { current = new CommentProperty(value); break; } case Property.HYPERLINK: { current = new HyperlinkProperty(value); break; } default: { throw new ArgumentException("Invalid type: " + type); } } if (previous != null) { previous._next = current; } else { _firstProperty = current; } } }
//private void addTaxonomyFieldValue(DataRow newRow, Property prop, object fieldValue) //{ // string[] strArray = fieldValue.ToString().Split('|'); // newRow[prop.Name] = string.Concat(strArray.GetValue(1).ToString(), ";#", strArray.GetValue(0).ToString()); //} public static void AssignFieldValue(ListItem listItem, Property prop) { FieldType ft = (FieldType)prop.MetaData.GetServiceElement <FieldType>(Constants.InternalProperties.FieldTypeKind); // https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.client.fieldtype.aspx switch (ft) { case FieldType.AllDayEvent: case FieldType.Attachments: case FieldType.CrossProjectLink: case FieldType.Recurrence: case FieldType.Boolean: listItem[prop.Name] = Convert.ToBoolean(prop.Value); break; case FieldType.DateTime: listItem[prop.Name] = TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse(prop.Value.ToString()), TimeZoneInfo.Local); break; case FieldType.Counter: case FieldType.MaxItems: case FieldType.ModStat: case FieldType.WorkflowEventType: case FieldType.WorkflowStatus: case FieldType.Integer: listItem[prop.Name] = Convert.ToInt32(prop.Value); break; case FieldType.Number: case FieldType.Currency: listItem[prop.Name] = Decimal.Parse(prop.Value.ToString(), NumberStyles.Any, NumberFormatInfo.CurrentInfo); break; case FieldType.Note: case FieldType.Computed: case FieldType.ThreadIndex: case FieldType.Threading: case FieldType.File: listItem[prop.Name] = prop.Value.ToString(); break; case FieldType.Guid: listItem[prop.Name] = Guid.Parse(prop.Value.ToString()); break; case FieldType.Lookup: //TODO: Move LookupMulti to constant if (string.Compare(prop.MetaData.GetServiceElement <string>(Constants.InternalProperties.SPFieldType), "LookupMulti") == 0) { assignLookupFieldTypeMulti(listItem, prop); } else { int LookupId = -1; if (int.TryParse(prop.Value.ToString(), out LookupId)) { listItem[(prop.Name).Substring(0, (prop.Name).Length - 2)] = LookupId; //This is done as Property name has a ID suffix to its name } } break; case FieldType.User: //TODO: Move UserMulti to constant if (string.Compare(prop.MetaData.GetServiceElement <string>(Constants.InternalProperties.SPFieldType), "UserMulti") == 0) { assignUserFieldTypeMulti(listItem, prop); } else { listItem[(prop.Name).Substring(0, (prop.Name).Length - 2)] = getUserId(prop.Value.ToString()); //This is done as Property name has a ID suffix to its name } break; case FieldType.URL: if (!string.IsNullOrEmpty(prop.Value as string)) { FieldUrlValue _url = new FieldUrlValue(); HyperlinkProperty hProp = prop as HyperlinkProperty; if (prop != null) { _url.Url = hProp.Link; _url.Description = hProp.Display; listItem[prop.Name] = _url; } } break; case FieldType.MultiChoice: string[] multiChoice = prop.Value.ToString().Split(new char[] { ';' }); listItem[prop.Name] = multiChoice; break; //TODO case FieldType.Invalid: Depending upon TypeAsString value. But this needs to be implemented case by case basis. case FieldType.Text: case FieldType.Choice: default: listItem[prop.Name] = prop.Value.ToString(); break; } }
public static void AddFieldValue(DataRow newRow, Property prop, ListItem listItem) { object fieldValue = listItem.FieldValues[prop.Name]; if (fieldValue == null) { return; } FieldType ft = prop.MetaData.GetServiceElement <FieldType>(Constants.InternalProperties.FieldTypeKind); switch (ft) { case FieldType.AllDayEvent: case FieldType.Attachments: case FieldType.CrossProjectLink: case FieldType.Recurrence: case FieldType.Boolean: newRow[prop.Name] = Convert.ToBoolean(fieldValue); break; case FieldType.DateTime: newRow[prop.Name] = TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse(fieldValue.ToString()), TimeZoneInfo.Local); break; case FieldType.Counter: case FieldType.MaxItems: case FieldType.ModStat: case FieldType.WorkflowEventType: case FieldType.WorkflowStatus: case FieldType.Integer: newRow[prop.Name] = Convert.ToInt32(fieldValue); break; case FieldType.Number: case FieldType.Currency: newRow[prop.Name] = Decimal.Parse(fieldValue.ToString(), NumberStyles.Any, NumberFormatInfo.CurrentInfo); break; case FieldType.Note: case FieldType.Computed: newRow[prop.Name] = fieldValue.ToString(); break; case FieldType.ThreadIndex: case FieldType.Threading: case FieldType.File: //This coulmn contains only reference of the actual file TODO : Either change the SOType in Maphelper or we might have to change the code here. //newRow[prop.Name] = fieldValue.ToString(); break; case FieldType.Guid: newRow[prop.Name] = Guid.Parse(fieldValue.ToString()); break; case FieldType.ContentTypeId: newRow[prop.Name] = Convert.ToString(fieldValue); break; case FieldType.Lookup: //TODO: Move LookupMulti to constant if (string.Compare(prop.MetaData.GetServiceElement <string>(Constants.InternalProperties.SPFieldType), "LookupMulti") == 0) { addMultiLookupFieldValue(newRow, prop, fieldValue); } else { FieldLookupValue fieldLookupValue = fieldValue as FieldLookupValue; if (fieldLookupValue != null) { if (!string.IsNullOrEmpty(fieldLookupValue.LookupValue)) { newRow[prop.Name] = string.Format("{0};#{1}", fieldLookupValue.LookupId, fieldLookupValue.LookupValue); newRow[prop.Name + Constants.InternalProperties.Suffix_Value] = fieldLookupValue.LookupValue.ToString(); } newRow[prop.Name + Constants.InternalProperties.Suffix_ID] = fieldLookupValue.LookupId.ToString(); } } break; case FieldType.User: if (string.Compare(prop.MetaData.GetServiceElement <string>(Constants.InternalProperties.SPFieldType), "UserMulti") == 0) { addMultiUserFieldValue(newRow, prop, fieldValue); } else { FieldUserValue fieldUserValue = fieldValue as FieldUserValue; if (fieldUserValue != null) { if (!string.IsNullOrEmpty(fieldUserValue.LookupValue)) { newRow[prop.Name] = string.Format("{0};#{1}", fieldUserValue.LookupId, fieldUserValue.LookupValue); newRow[prop.Name + Constants.InternalProperties.Suffix_Value] = fieldUserValue.LookupValue.ToString(); } newRow[prop.Name + Constants.InternalProperties.Suffix_ID] = fieldUserValue.LookupId.ToString(); } } break; case FieldType.URL: HyperlinkProperty hyperlinkProperty = new HyperlinkProperty(); FieldUrlValue fieldUrlValue = fieldValue as FieldUrlValue; if (fieldUrlValue.Url.Length > 0) { hyperlinkProperty.Display = fieldUrlValue.Description; hyperlinkProperty.Link = fieldUrlValue.Url; newRow[prop.Name] = hyperlinkProperty.Value.ToString(); } break; //Not Required as Fieldtype is saved according to its outPutType //case FieldType.Calculated: // FieldCalculated calcVar = fieldValue as FieldCalculated; // AddCalculatedFieldValue(newRow,prop,calcVar.OutputType,fieldValue); // break; case FieldType.MultiChoice: string[] multiChoice = fieldValue as string[]; if (multiChoice.Length > 0) { string UserMultiValue = string.Empty; StringBuilder strMulti = new StringBuilder(); foreach (string field in multiChoice) { strMulti = strMulti.AppendFormat("{0};", field.ToString()); } if (strMulti.Length > 0) { UserMultiValue = strMulti.ToString().Substring(0, strMulti.Length - 1); } newRow[prop.Name] = UserMultiValue.ToString(); } break; case FieldType.Invalid: if (string.Compare(prop.MetaData.GetServiceElement <string>(Constants.InternalProperties.SPFieldType), Constants.SharePointProperties.TaxanomyFieldType) == 0) { addTaxonomyFieldValue(newRow, prop, fieldValue); } else if (string.Compare(prop.MetaData.GetServiceElement <string>(Constants.InternalProperties.SPFieldType), Constants.SharePointProperties.TaxanomyFieldTypeMulti) == 0) { addMultiTaxonomyFieldValue(newRow, prop, fieldValue); } else { newRow[prop.Name] = fieldValue.ToString(); } break; //TODO case FieldType.Invalid: Depending upon TypeAsString value. But this needs to be implemented case by case basis. case FieldType.Text: case FieldType.Choice: default: newRow[prop.Name] = fieldValue.ToString(); break; } }
set => SetValue(HyperlinkProperty, value);