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...
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
Get the target frame of shortcut link of the CurrentPage
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.
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:
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:
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.