Shortcut and external links property in EPiServer

The reason for writing this is mostly to have it stored for myself, but I also had some problems with this property on a migration project that I have been...

  • 6 July 2011
  • 0

The reason for writing this is mostly to have it stored for myself, but I also had some problems with this property on a migration project that I have been doing. So while trying to solve that problem I searched for the property names of the 'shortcut' and 'external links' and didn't find that much.

General about EPiServers property for Shortcut and external links

The purpose is to first of all see if there is a link at all. Since this could be either to a page on the site or an external url, therefore we need to extract it differently depending on what type it is.

These are the Link types:

  • Link to this page
  • Shortcut to page in EPiServer CMS
  • Fetch data from page in EPiServer CMS
  • Link to page on another website
  • No link, only text

Get the PageShortcutType of the CurrentPage

   1: // Get the link type
   2: PageShortcutType propertyLinkType = CurrentPage.LinkType;
   4: // Could also be achieved like this, and here you could also see the property name:
   5: propertyLinkType = (PageShortcutType)Enum.Parse(typeof(PageShortcutType), CurrentPage.Property["PageShortcutType"].ToString());

Get the target frame of shortcut link of the CurrentPage

   1: // Get the target frame
   2: PropertyFrame targetFrame = CurrentPage.Property["PageTargetFrame"] as PropertyFrame;
   4: // Get the target value, the value you set in the Target attribute on links
   5: var target = targetFrame.FrameName;

Get hold of the internal links – PageShortcutLink. PageExternalURL or the PageLink

These exists if the ShortcutType is set to ‘Link to this page’ or ‘Shortcut to page in EPiServer CMS’. All of these is of type PageReference.

  • PageLink – is the link to the page it self.
  • PageShortcutLink – exists if the PageShortcutType is set to “Shortcut to page in EPiServer CMS” or PageShortcutType.Shortcut

Get hold of external links

If the ShortcutType is set to ‘Link to page on another website’ the LinkUrl and StaticLink will be set to the value defined the property field ‘External Link’. So to get hold of the URL if the ShortcutType is PageShortcutType.External then just request the CurrentPage.LinkUrl.


A small note is that the PageExternalURL property is the SimpleAddress of the page.

   1: // Get the simple address of the CurrentPage
   2: var simpleAddress = CurrentPage.Property["PageExternalUrl"].Value as string;

The  LinkUrl will always give you the target URL of the page in all cases.

Simple addresses with FindPagesWithCriteria

If you would like to get hold of the page with a specific simple address this is the way to do it:

var critcol = new PropertyCriteriaCollection();
var crit = new PropertyCriteria
                Required = true, 
                Condition = EPiServer.Filters.CompareCondition.Equal, 
                Name = "PageExternalURL", 
                Type = PropertyDataType.String, 
                Value = "~/" + pageSimpelAddress.Trim(new char[] {'/'}) // necessary for PageExternalURL
// Remove initial "/"  
var pagecol = DataFactory.Instance.FindPagesWithCriteria(PageReference.RootPage, critcol);

Note that to get hold of the PageExternalURL you need to add ~/ infront of the URL!

Problems with pages with shortcut links after upgrade? Here is a small note for you!

I got a little headache during the upgrade to CMS 6 R2 from pages with shortcut links. After some research and a very good tip from: Fredrik Tjarnberg I found out that it is actually a bug in the upgrade script.

So first of all run this sql-script to see if you have any pages affected by this:

select fkPageId from tblworkpage
where tblworkpage.linktype in (1,4)

This will list all pages with linktype other than the standard one: “Link to this page”.

Then before doing the upgrade download this updated script (Found on Fredrik Tjarnbergs blog post - Important: Potential issues when upgrading to CMS6 R2)  to the folder where the upgrade scripts for versopm 6.1.379.0 resides (normally: c:\Program Files x86\EPiServer\CMS\6.1.379.0\Upgrade\Database\sql ).

Then just complete the update.