Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

How to tell if IContent is an asset or a page link?

Vote:
 

Basically, I have a LinkItemCollection property on a block, and when it's displayed I'd like to add special HTML if it's an external link or if it's a file (pdf or word file or similar) rather than an internal episerver page. 

I already have an "IsInternal()" method that examines the Href and historically works well, but struggling to find a method to tell the difference between different internal links, page vs image vs pdf etc.

#201329
Feb 14, 2019 16:21
Vote:
 

When you have some IContent you can use the standard c# is check

if (content is PageData)
{
   LOGIC
}

If the type is castable to that type it will be true. Use multiple cases for each on to determine what type it is.

#201330
Feb 14, 2019 16:42
Vote:
 

Hi Scott, are you suggesting if it casts to pageData that it is then not a pdf or image or similar? I dont have a concise list of file types it may be.

#201331
Feb 14, 2019 16:51
Vote:
 

PageData is the base type for all pages

BlockData is the base type for blocks

MediaData is the base type for all assets

If you need to specificly check for a type check for that e.g. ImageFile if that's the type in your solution to check it's an image. 

#201333
Feb 14, 2019 17:01
Vote:
 

Thanks Scott, I knew there'd be a reasonally simple way to do it.

#201334
Feb 14, 2019 17:19
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.