Copied to clipboard

Flag this post as spam?

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


  • Adam Conde 12 posts 58 karma points
    Jul 22, 2009 @ 20:43
    Adam Conde
    0

    Retrieve node type from ID

    How can i tell what type of object is represented for a specified ID?

    Basically given an ID like 1045 i want to be able to determine if this is a Member, MemberGroup, Document, etc...

    If nothing else, i'd just like to confirm that the specified ID is the ID of an existing MemberGroup.

     

    Thanks!

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 22, 2009 @ 20:55
    Dirk De Grave
    100

    Hi Adam,

     

    Best solution I'm aware of for this is to look after the nodeObjectType property on your node object (returns a guid) and compare it with existing guid for the different node types (content, media, stylesheet, ...)

    For example: 

    public static Guid _objectType = new Guid("b796f64c-1f99-4ffb-b886-4bf4bc011a9c"); // static Guid on the Media class

    and compare this with the myNode.nodeObjectType (which is also a guid). If both are equal, then node myNode is of that type.

     

    Hope this helps.

     

    Regards,

    /Dirk

     

     

  • Adam Conde 12 posts 58 karma points
    Jul 22, 2009 @ 20:58
    Adam Conde
    0

    How do i know what Guid is for a given type?  Is this stored in a table?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 22, 2009 @ 21:39
    Dirk De Grave
    0

    Adam,

     

    As that guid is a static field on the type! As in example above, the guid is for the MediaType (such as the File, Folder and Image from the media section)

    A node mediaNode is of type Media if

    mediaNode._objectType.ToString() == new Guid("").ToString();

     

    Does that clarify things?

     

    Cheers,

    /Dirk 

  • Adam Conde 12 posts 58 karma points
    Jul 22, 2009 @ 23:56
    Adam Conde
    0

    Thanks for your help. I wrote this case statement to determine the object type:

     public static System.Type GetNodeType(int nodeId)
            {
          System.Type t = null;
            CMSNode n = new CMSNode(nodeId);
                    switch (n.nodeObjectType.ToString().ToUpper())
                    {
                        case "A2CB7800-F571-4787-9638-BC48539A0EFB":
                            t = typeof(umbraco.cms.businesslogic.web.DocumentType);
                            break;
                        case "C66BA18E-EAF3-4CFF-8A22-41B16D66A972":
                            t = typeof(umbraco.cms.businesslogic.web.Document);
                            break;
                        case "9B5416FB-E72F-45A9-A07B-5A9A2709CE43":
                            t = typeof(umbraco.cms.businesslogic.member.MemberType);
                            break;
                        case "6FBDE604-4178-42CE-A10B-8A2600A2F07D":
                            t = typeof(umbraco.cms.businesslogic.template.Template);
                            break;
                        case "366E63B9-880F-4E13-A61C-98069B029728":
                            t = typeof(umbraco.cms.businesslogic.member.MemberGroup);
                            break;
                        case "9F68DA4F-A3A8-44C2-8226-DCBD125E4840":
                            t = typeof(umbraco.cms.businesslogic.web.StyleSheet);
                            break;
                        case "39EB0F98-B348-42A1-8662-E7EB18487560":
                            t = typeof(umbraco.cms.businesslogic.member.Member);
                            break;
                        case "4EA4382B-2F5A-4C2B-9587-AE9B3CF3602E":
                            t = typeof(umbraco.cms.businesslogic.media.MediaType);
                            break;
                        case "B796F64C-1F99-4FFB-B886-4BF4BC011A9C":
                            t = typeof(umbraco.cms.businesslogic.media.Media);
                            break;
                        case "01BB7FF2-24DC-4C0C-95A2-C24EF72BBAC8":
                            t = typeof(umbraco.cms.businesslogic.RecycleBin);
                            break;
                        default:
                            break;
            }
            return t;
        }
Please Sign in or register to post replies

Write your reply to:

Draft