Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Sitecore 5.3 to 6.0 problems

Modified: 2010/06/02 11:27 by k.schepens - Categorized as: Sitecore
Recently we have migrated a website from Sitecore 5.3 to 6.0. Although the migration went rather smoothly, we did run into a number of (partly unexpected) problems. In this article we will describe the problems we have encountered and how they have been solved.

In this article we will only focus on problems in migrating the code (both code-behind and XSLT). Migrating the content is not discussed.

Edit

Code-behind

The advantage of code-behind problems is that they are easy to detect because they produce compile warnings or errors. First we will discuss the compile warnings and then the compile errors.

Edit

Warnings

The following code snippet produced a compile warning:

Item itemSearchSite = this.GetSitecoreItemByGuid(Settings.Default.Guid_SearchSite);
url = Util.ProcessLink(itemSearchSite.Paths.GetFriendlyUrl());

The problem is the method GetFriendlyUrl which is deprecated in Sitecore 6.0. This code snippet has been replaced by the following:

Item itemSearchSite = this.GetSitecoreItemByGuid(Settings.Default.Guid_SearchSite);
url = Util.ProcessLink(Sitecore.Links.LinkManager.GetItemUrl(itemSearchSite));

The following code snippet also produced a compile warning:

Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem(
    new Sitecore.Data.ID(itemId), 
    Sitecore.Globalization.Language.Current
  );
if (item.Master != null && item.Master.Name == "HU-RES-Section")

The problem here is the property Master which is deprecated and has been replaced by the property Branch. This code snippet has therefore been replaced by the following:

Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem(
    new Sitecore.Data.ID(itemId), 
    Sitecore.Globalization.Language.Current
  );
if (item.Branch != null && item.Branch.Name == "HU-RES-Section")

And the last compile warning was caused by the following code snippet:

html = Sitecore.Data.Fields.HtmlField.ConvertToXHtml(html);

The method ConvertToXHtml has also been deprecated. Here is the Sitecore 6 version of this code snippet:

html = Sitecore.Layouts.XHtml.Convert(html);

Edit

Errors

In a web service the following code snippet was used to login into Sitecore:

DomainAccessResult result = Sitecore.Context.Domain.Login(username, password);
LoginResult loginResult = new LoginResult { Message = result.Message, Success = result.Success };
return loginResult;

This produces a compile error because in Sitecore 6 the method Sitecore.Context.Domain.Login doesn’t exist anymore. This code snippet has been rewritten using Sitecore.Security.Authentication.AuthenticationManager.Login:

bool loginSucceededYN = Sitecore.Security.Authentication.AuthenticationManager.Login(username, password);
string loginMessage = (loginSucceededYN ? "Login succeeded." : "Login failed. Check your username and password.");
DomainAccessResult result = new DomainAccessResult(loginSucceededYN, loginMessage);
LoginResult loginResult = new LoginResult { Message = result.Message, Success = result.Success };
return loginResult;

PublishOptions

PublishOptions' source database and target database are now set on construction time.

Old code:
PublishOptions myOptions = new PublishOptions(PublishMode.SingleItem, Sitecore.Data.Managers.LanguageManager.DefaultLanguage, DateTime.Now);

...

// Set the databases
myOptions.SourceDatabase = sourceDatabase;
myOptions.TargetDatabase = targetDatabase;

Replaced by:

PublishOptions myOptions = new PublishOptions(sourceDatabase, targetDatabase, PublishMode.SingleItem, Sitecore.Data.Managers.LanguageManager.DefaultLanguage, DateTime.Now);
Edit

XSLT

The awkward thing about migration problems in the XSLT’s is that they do not produce warnings or errors. Instead they usually just return nothing, which make them difficult to detect. You really have to look carefully at the output of a XSLT to find these problems.

In the Sitecore 5.3 version of an XSLT the following code snippet was used to display a list of links to downloadables:

<xsl:for-each select="$downloads/item">
  <a target="_New">
    <xsl:attribute name="href">
      <xsl:value-of select="sc:fld('File',.,'src')"/>
    </xsl:attribute>
    <sc:text field="@name" />
  </a>
</xsl:for-each>

In Sitecore 6 this didn’t seem to produce any output. Looking at the HTML we noticed that the list of links was actually there, but the hyperlinks had no text. Apparently deriving the name of an content item by using @name does not work in Sitecore 6 and always produces an empty string. This problem could be fixed by replacing @name by sc:fld('@name', .):

<xsl:for-each select="$downloads/item">
  <a target="_New">
    <xsl:attribute name="href">
      <xsl:value-of select="sc:fld('File',.,'src')"/>
    </xsl:attribute>
    <xsl:value-of select="sc:fld('@name', .)"/>
  </a>
</xsl:for-each>

And finally the following code snippet was used in Sitecore 5.3 for deriving the url to an item from the media library:

<xsl:variable name="guid" select="sc:fld('FlashContent', $sc_currentitem)" />
<xsl:variable name="logo" select="sc:item( $guid, . )" />
<xsl:variable name="flashitem" select="sc:fld('Path', $logo)" />

In Sitecore 6 this always returned an empty string as well, i.e. the variable flashitem was always empty. Apparently in Sitecore 6 an item from the media library does not contain a field called path anymore. To solve this the method GetMediaUrl has been used:

<xsl:variable name="guid" select="sc:fld('FlashContent', $sc_currentitem)" />
<xsl:variable name="logo" select="sc:item( $guid, . )" />
<xsl:variable name="flashitem" select="sc:GetMediaUrl($logo)" />

 © Evident Interactive BV