Link to PDF from a Nav item


Is it possible to link to a file like a pdf directly from a sub or main nav item into a new tab/window? If so, what's the best way to do it?


Apr 28, 2015 17:57

Hi Nathan,

What version of CMS are developing for?

I would recommend having a content reference (if on CMS 7.5+) on a page type and use that together with UrlResolver to link to a file.

If you are on CMS 7 and below then you could add a property of type Url to link to a file or create a page type that has logic to redirect to a file (the URL will be to the page and not the file though).



Apr 28, 2015 22:54

It's not an uncommon requests but it really is terrible for the end-user.

A link to a PDF should clearly reveal that it is and it's also suggested to display the target's file size. Not nice to have in any navigation area.

Apr 29, 2015 9:26

In case you're using MVC and EPiServer CMS 7.5+

You can define a new page type as Toni suggested:

[ContentType(GUID = "c5aabd75-eeec-41e1-bfbf-63d1f98b6ba8")]
public class FileLinkPage : PageData
    public virtual ContentReference File { get; set; }

And have something like this in the view:

<ul class="nav">
        var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
        var children = contentLoader.GetChildren<IContent>(ContentReference.StartPage);
        foreach (var child in children)
                @if (child is FileLinkPage)
                    var fileLinkPage = (FileLinkPage)child;
                    if (!ContentReference.IsNullOrEmpty(fileLinkPage.File))
                        <a href="@Url.ContentUrl(fileLinkPage.File)" target="_blank">@fileLinkPage.Name</a>
                    <a href="@Url.ContentUrl(child.ContentLink)">@child.Name</a>


1. It's not a good practice to have this logic in the view (ServiceLocators, etc.) You can borrow the logic from AlloyTech and create navigation links somewhere inside IPageViewModel > LayoutModel
2. It will not filter container pages. You should check if child page have a template.

Hope this helps :)

Apr 29, 2015 9:47

Johan, believe me, I know! But our client base can be pretty insistent when they want to be, particularly about bad ideas.

Thank you, Dejan and Toni for your help.

Apr 29, 2015 14:35
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.