November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
- You can use IContentSoftLinkRepository.Load(ContentReference contentLink, bool reversed) to find the SoftLink (basically links that are in contentarea for example, IIRC), and then iterate over the Property to check if there is any ContentReference property and where it is pointing to.
Dynamically looping through all the properties although you'd have to look in to content areas and any blocks if you wanted to go beyond the page. I think there's been blog or fourm with example core for this
Hi Robert,
There is nothing out-of-the-box.
Combining what Quan and Scott are saying you'd have to do something like this:
public ICollection<ContentReference> GetReferencesFromContent(ContentReference contentLink)
{
// Service locator used purely for example purposes :)
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var contentSoftLinkRepository = ServiceLocator.Current.GetInstance<IContentSoftLinkRepository>();
var content = contentLoader.Get<IContent>(contentLink);
var contentLinks = new List<ContentReference>();
foreach (var property in content.Property)
{
// Get straight content references
if (property.PropertyValueType == typeof(ContentReference))
{
var link = property.Value as ContentReference;
if (!ContentReference.IsNullOrEmpty(link))
{
contentLinks.Add(link);
}
}
// Get IList<ContentReference> links
if (typeof(IEnumerable<ContentReference>).IsAssignableFrom(property.PropertyValueType))
{
var links = property.Value as IEnumerable<ContentReference>;
if (links != null)
{
contentLinks.AddRange(links);
}
}
}
// Get links from ContentAreas, LinkItemCollection and XhtmlStrings
var softLinks = contentSoftLinkRepository.Load(contentLink).Where(x =>
x.SoftLinkType == ReferenceType.PageLinkReference || x.SoftLinkType == ReferenceType.ImageReference);
contentLinks.AddRange(softLinks.Select(x => x.ReferencedContentLink));
return contentLinks.Distinct().ToList();
}
Definitely don't think this is comprehensive, but hopefully it gives you a starting point.
I am wondering if there is a way to find out all content that a content is referencing (not being referenced by which can be found by using GetReferencesToContent).