Vulnerability in EPiServer.Forms
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.
Check out softlink class in api to get references.
That will give you a list of softlinks that contain pagelink as property. Use UrlResolver to get the url from that...
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.
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));
var content = contentRepository.Get<???>(
You can fetch the content as IContent
.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.
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,