November Happy Hour will be moved to Thursday December 5th.

Find usages of images from code

Vote:
 

Hi,

I have, from code, moved some images from different folders to one and I hoped that name conflicts whould be resolved by overwriting. That wasn't the case, instead there are two or more "versions" of the same file but with different ContentReferences. Then I want to delete the duplicated files that are not referenced by a page but I'm not sure which one that's used (it differs). When I remove an image in edit mode I get a warning if the image is used by a page, but from code I don't find a way to findout which pages that use a specific image. Does anyone know how to do that?

#122705
Jun 10, 2015 16:20
Vote:
 

I think you could go with:

var softLinkRepos = ServiceLocator.Current.GetInstance<ContentSoftLinkRepository>();
            var softLinks = softLinkRepos.Load(contentLink, true);

If I understood the question correct. :)

#122706
Jun 10, 2015 16:52
Vote:
 

Hi Erik,

Thank you, I've tried the ContentSoftLinkRepository without success, I get 0 SoftLinks back. I'm testing with two images where one of them is used on a page. But both images and the page have 0 softlinks and I try three variants
_contentSoftLinkRepository.Load(content.ContentGuid, true)
_contentSoftLinkRepository.Load(content.ContentGuid, false)
_contentSoftLinkRepository.Load(content.ContentLink).But no result from any of them.

#122716
Jun 11, 2015 7:36
Vote:
 

Apperently there is a method on the IContentRepository called GetReferencesToContent. Try that one instead. :)

var references = ServiceLocator.Current.GetInstance<IContentRepository>().GetReferencesToContent(page.ContentLink, false);

#122732
Jun 11, 2015 10:49
Vote:
 

That did the trick, thank you Erik!

#122745
Jun 11, 2015 13:40
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.