Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jerode 44 posts 159 karma points
    Aug 27, 2015 @ 13:35
    Jerode
    0

    Get Id of Custom DataType

    My goal is to get a list of all the values of a custom DataType.

    Example:
    DataType Name: ContentVisibility
    Pre Values: Public Only, Private Only, Both Public and Private
    

    How do I get access to it?

    var dataTypeId = umbraco.cms.businesslogic.datatype.DataTypeDefinition.GetAll().First(d => d.Text == "ContentVisibility").Id;
    

    This is obsolete and will be removed. What is the alternative to get the Id of a specific datatype?

    I ultimately need to get all the possible values of a DataType and have to resort to using an enumerator to go through all the prevalues in the DataType.

    public static Dictionary<int, object> GetPrevalues(int dataTypeId)
    {
        XPathNodeIterator preValueRootElementIterator = umbraco.library.GetPreValues(dataTypeId);
        preValueRootElementIterator.MoveNext(); //move to first 
        XPathNodeIterator preValueIterator = preValueRootElementIterator.Current.SelectChildren("preValue", "");
        var retVal = new Dictionary<int, object>();
    
        while (preValueIterator.MoveNext())
        {
            retVal.Add(Convert.ToInt32(preValueIterator.Current.GetAttribute("id", "")), preValueIterator.Current.Value);
        }
        return retVal;
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft