Try our conversational search powered by Generative AI!

Exporting all the page links where there is a link to PDF in website with details of category tag, published date, PDF link and page URL.



We have requirement to fetch all page links with PDF reference in it.Is there a way we can export all the pages with a PDF link with detail of category tag, published date, PDF link and page URL in Optimizely CMS 12 using code or any other way.



Mar 06, 2024 7:58

Hi Deepa,

You sure can do this using code, this might not be the optimial way of doing it, however it should give you guidance.

PDF's as I understand it should be stored as a media type, therefore we can use 'IContentLoader' to get all content that is media, if you have a specific media type for PDF's then better to use this.

public class MediaService
    private readonly IContentLoader _contentLoader;

    public MediaService(IContentLoader contentLoader)
        _contentLoader = contentLoader ?? throw new ArgumentNullException(nameof(contentLoader));

    public IEnumerable<ContentReference> GetAllMediaReferences()
        var mediaRoot = ContentReference.GlobalBlockFolder;
        var mediaFolders = _contentLoader.GetChildren<MediaData>(mediaRoot);

        var allMediaReferences = new List<ContentReference>();
        foreach (var mediaFolder in mediaFolders)
            var mediaReferences = GetMediaReferencesRecursive(mediaFolder.ContentLink);

        return allMediaReferences;

    private IEnumerable<ContentReference> GetMediaReferencesRecursive(ContentReference folderReference)
        var mediaReferences = new List<ContentReference>();

        var mediaItems = _contentLoader.GetChildren<MediaData>(folderReference);
        mediaReferences.AddRange(mediaItems.Select(media => media.ContentLink));

        var subFolders = _contentLoader.GetChildren<ContentFolder>(folderReference);
        foreach (var subFolder in subFolders)
            var subFolderMediaReferences = GetMediaReferencesRecursive(subFolder.ContentLink);

        return mediaReferences;

Once you have all the media you can loop over this and then find the page / block that is using the media:

public IEnumerable<ContentReference> GetContentReferencesUsingMedia(ContentReference mediaContentReference)
        return _contentSoftLinkRepository.Load(mediaContentReference, false)
            .Select(link => link.OwnerContentLink);

Additionally you might need to apply some filtering on the media to filter out images, videos, etc.

Hopefully this will help guide you to a solution.


Mar 06, 2024 9:42
Deepa Puranik - Mar 07, 2024 8:02
Thank you Paul for help.
* 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.