Finding properties with references to images

J
J
Vote:
 

Hello!

Im new to EPiserver so im very much out of the loop on lots of things, but i thought maybe i could get some help here.

What i want to do is basically find if a page has a property that holds a reference to an image. Since there are seemingly many types of properties that can hold images(ContentAreas, ContentReferences, blocks, imageblocks within content areas etc.). Im not sure what the best course would be to look through all these properties within this page that possibly could hold a reference to an image.

I have this: 

var writablePage = _contentRepository.Get<NewsPage>(pageLink).CreateWritableClone() as NewsPage;

Which lets me see and adjust the properties of this page as i want, which is good and all. But what would be the best way go about to find all the various types of properties that can hold an image reference?

#230488
Nov 06, 2020 10:31
Vote:
 

Hi,

Haven't tested this code. But something along these lines might work:

var links = ServiceLocator.Current.GetInstance<IContentSoftLinkRepository>()
    .Load(pageLink);

// Not sure if this works on internal links...
var hasImage1 = links.Any(x => x.SoftLinkType == ReferenceType.ImageReference);

// This will only evaluate internal links
var hasImage2 = links.Any(x => _contentRepository.TryGet<ImageData>(x.ReferencedContentLink, out _));
#230586
Edited, Nov 09, 2020 11:30
* 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.