Try our conversational search powered by Generative AI!

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


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.

Feb 14, 2019 16:21

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

if (content is PageData)

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

Feb 14, 2019 16:42

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.

Feb 14, 2019 16:51

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. 

Feb 14, 2019 17:01

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

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.