Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 333
YashG99 Avatar asked Feb 06 '12 14:02

YashG99


1 Answers

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

like image 195
Sean Kearney Avatar answered Sep 21 '22 01:09

Sean Kearney