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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With