Beispiel #1
0
        //public static string GetUrl(this SPListItem item, string fieldName)
        //{
        //    object value = GetValue(item, fieldName);

        //    return GetUrl(value);
        //}

        //public static string GetUrl(this SPListItem item, Guid fieldId)
        //{
        //    object value = GetValue(item, fieldId);

        //    return GetUrl(value);
        //}

        //public static int GetRating(this SPListItem item, string fieldName)
        //{
        //    object value = GetValue(item, fieldName);

        //    return GetRating(value);
        //}

        //public static int GetRating(this SPListItem item, Guid fieldId)
        //{
        //    object value = GetValue(item, fieldId);

        //    return GetRating(value);
        //}

        //public static TaxonomyFieldValue GetTaxonomyValue(this SPListItem item, Guid fieldId)
        //{
        //    var value = item[fieldId];

        //    TaxonomyFieldValue ret = value != null
        //                                ? (TaxonomyFieldControl.GetTaxonomyValue(value.ToString())
        //                                   ?? new TaxonomyFieldValue(string.Empty))
        //                                : new TaxonomyFieldValue(string.Empty);

        //    return ret;
        //}

        //public static TaxonomyFieldValue GetTaxonomyValue(this SPListItem item, string fieldName)
        //{
        //    var value = item[fieldName];

        //    TaxonomyFieldValue ret = value != null
        //                                 ? (TaxonomyFieldControl.GetTaxonomyValue(value.ToString())
        //                                    ?? new TaxonomyFieldValue(string.Empty))
        //                                 : new TaxonomyFieldValue(string.Empty);

        //    return ret;
        //}

        //public static TaxonomyFieldValueCollection GetTaxonomyValues(this SPListItem item, Guid fieldId)
        //{
        //    var value = item[fieldId];

        //    TaxonomyFieldValueCollection ret = value != null
        //                                           ? (TaxonomyFieldControl.GetTaxonomyCollection(value.ToString())
        //                                              ?? new TaxonomyFieldValueCollection(string.Empty))
        //                                           : new TaxonomyFieldValueCollection(string.Empty);

        //    return ret;
        //}

        //public static TaxonomyFieldValueCollection GetTaxonomyValues(this SPListItem item, string fieldName)
        //{
        //    var value = item[fieldName];

        //    TaxonomyFieldValueCollection ret = value != null
        //                                           ? (TaxonomyFieldControl.GetTaxonomyCollection(value.ToString())
        //                                              ?? new TaxonomyFieldValueCollection(string.Empty))
        //                                           : new TaxonomyFieldValueCollection(string.Empty);

        //    return ret;
        //}

        //public static string GetTaxonomyLabel(this SPListItem item, Guid fieldId)
        //{
        //    return GetTaxonomyValue(item, fieldId).Label;
        //}

        //public static string GetTaxonomyLabel(this SPListItem item, string fieldName)
        //{
        //    return GetTaxonomyValue(item, fieldName).Label;
        //}

        //public static string[] GetTaxonomyLabels(this SPListItem item, Guid fieldId)
        //{
        //    return GetTaxonomyValues(item, fieldId).Where(@tax => tax.Label != null).Select(@tax => tax.Label).ToArray();
        //}

        //public static string[] GetTaxonomyLabels(this SPListItem item, string fieldName)
        //{
        //    return GetTaxonomyValues(item, fieldName).Where(@tax => tax.Label != null).Select(@tax => tax.Label).ToArray();
        //}

        public static void SetTaxonomyValue(this SPListItem item, string fieldName, string value, bool addIfDoesNotExist)
        {
            TaxonomyField taxonomyField = (TaxonomyField)item.Fields[fieldName];

            if (taxonomyField.AllowMultipleValues)
            {
                TaxonomyFieldValueCollection taxValue =
                    TaxonomyHelper.GetTaxonomyFieldValues(item.Web.Site, taxonomyField, new[] { value }, addIfDoesNotExist);
                taxonomyField.SetFieldValue(item, taxValue);
            }
            else
            {
                TaxonomyFieldValue taxValue = TaxonomyHelper.GetTaxonomyFieldValue(item.Web.Site, taxonomyField, value, addIfDoesNotExist);
                taxonomyField.SetFieldValue(item, taxValue);
            }
        }
Beispiel #2
0
        public static void SetTaxonomyValues(this SPListItem item, string fieldName, bool addIfDoesNotExist, params string[] values)
        {
            TaxonomyField taxonomyField = (TaxonomyField)item.Fields[fieldName];

            if (taxonomyField.AllowMultipleValues)
            {
                TaxonomyFieldValueCollection taxValue = TaxonomyHelper.GetTaxonomyFieldValues(item.Web.Site, taxonomyField, values, addIfDoesNotExist);
                taxonomyField.SetFieldValue(item, taxValue);
            }
            else
            {
                TaxonomyFieldValue taxValue = values != null && values.Length > 0
                                                  ? TaxonomyHelper.GetTaxonomyFieldValue(item.Web.Site, taxonomyField, values[0], addIfDoesNotExist)
                                                  : new TaxonomyFieldValue(taxonomyField);

                taxonomyField.SetFieldValue(item, taxValue);
            }
        }