Try our conversational search powered by Generative AI!

Find page an asset is on



Is there a way in c# to find the page(s) that a certain asset such as an image is on albeit a page or block on a page. Ideally I would like an asset search library and allows the user to click on the a link that will take them to the image on the page.



Feb 23, 2016 16:20

Check out softlink class in api to get references.

Feb 23, 2016 16:44

That will give you a list of softlinks that contain pagelink as property. Use UrlResolver to get the url from that...

Feb 23, 2016 16:47

Hi Jonathan,

If you're using the latest version of EPiServer CMS, you can try the following code:

var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var content = contentRepository.Get<ImageData>(new ContentReference(87));
var references = contentRepository.GetReferencesToContent(content.ContentLink, true).ToList();

I used IContentSoftLinkRepository for Blocks and Pages, but it doesn't return correct results for Assets.

Feb 23, 2016 18:11

Great - but how would you dynamically know what Data Type the asset is? For example Video, Pdf, Image etc for this bit of the code: var content = contentRepository.Get<???>(new ContentReference(87));

Feb 23, 2016 18:18

You can fetch the content as IContent

Feb 23, 2016 19:28

.Get<MediaData>(mediaReference) as Image data



are two ways to get what type of media content you get...or use IContent like Dejan says if you don't even know if it is media.

Feb 23, 2016 21:18

Hi, These are all great replies and work - unfortunately it is very slow as I have lots of assets and lots of pages - it takes about 1 minute to get all the data back.

I think ill give this idea a miss - but thanks for all your help guys,


Feb 24, 2016 10:54
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.