Search code examples
sitecoresitecore6sitecore-media-library

Checking the type of a link in Sitecore


I have a 'General Link' field in one of my pages in Sitecore. This field basically specifies the link of a video file which is used to play a video.

Now, what I am trying to do is, check if the type of this link, whether the user has uploaded a link as an internal link, media or an external link. I need this info as, depending upon the type of the link, I need to perform some actions accordingly.

Is there a way to do check the type of a link in Sitecore?


Solution

  • 1st you need to get the field off of your item.

    Sitecore.Data.Fields.LinkField field = Sitecore.Context.Item.Fields["FIELD_NAME"];
    

    Then, you can inspect various properties of your field.

    bool isInternal = field.IsInternal;
    bool isMedia = field.IsMediaLink;
    string linkType = field.LinkType;
    

    The various LinkType values are internal, external, media, anchor, mailto, and javascript