Wednesday, 18 August 2010

Using Sitecore with Firefox, Chrome and other browsers

Sitecore recommends the use of IE for its client. When trying to log in with Firefox or Chrome (and presumably others), you don't get the option of viewing the desktop. There is a way you can override this behaviour. Open Sitecore in IE and go to the User Manager. Select your account and click Edit to bring up the "Edit User" dialogue. Click on the Profile tab and set the start URL to "Desktop". Save your changes and then try logging in with Firefox, etc. You should now see the full desktop.

Tuesday, 15 June 2010

Sitecore link fields put /home in the target URL's href

When using sc:fld('fieldname', ., 'url') in an XSLT rendering to get a link field's target URL, you will find that the href includes '/home'. This is rarely desirable. Thankfully, it's easy to solve. Simply use sc:fld('fieldname', ., 'id') instead to get the target ID. You can then pass the ID to sc:path().

Tuesday, 23 March 2010

How to remove an apostrophe from a string in Sitecore XSLT

Given a variable named "string", you can remove apostrophes by declaring a variable to hold the apostrophe and then passing that to the sc:Replace method:

<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="string"
select="sc:Replace( $input, $apos, '' )" />

Tuesday, 17 November 2009

The solution is offline because its associated Team Foundation Server is offline

When opening a solution in Visual Studio 2008, I kept getting the following message in the Output window:

This solution is offline. [Team Foundation Server:
http://server:8080/]
The solution is offline because its associated
Team Foundation Server is offline.

I kept having to go into the "change source control" and re-bind the solution. After a while, this began to get annoying. Then I found this post: http://www.eggheadcafe.com/software/aspnet/33487526/connecting-automatically.aspx. It turned out the solution was to set some registry keys. I navigated to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers\ and changed "Offline" to 0 and "AutoReconnect" to 1. I've no idea how these got reset! (Please back-up your registry first if you want to try the same.)

Friday, 13 November 2009

System.ArgumentException: Illegal characters in path

This exception caused me a headache for an hour today on a development web site. After various rebuilds failed to cure the issue, I found out that the aspnet_wp.exe process had somehow become corrupted. Re-saves of the web.config file didn't help, so I opened Task Manager, killed the process and was back up and working again.

Wednesday, 28 October 2009

Get a list of all Sitecore Items tagged with specific multilist items

If you wish to return all items in the content tree that have been tagged with a specific multilist item, you might be tempted to use Sitecore.Context.Database.SelectSingleItem(), passing it an XPath query. The problem with this is that performance degrades as the content tree grows. A far more efficient way is to use the GetReferrers method of the LinkDatabase class as shown below:

Database db = Sitecore.Context.ContentDatabase;

LinkDatabase linkDb = Globals.LinkDatabase;

// lookupItem is the multilist item
ItemLink[] links = linkDb.GetReferrers( lookupItem );

foreach( ItemLink link in links )
{
Item linkedItem = db.Items[link.SourceItemID];
// Process item...
}

Monday, 12 October 2009

Example Useful C# Extension Functions

Here are a few extension functions that I find useful:


public static bool IsNullOrEmpty(
this string expression )
{
bool result = string.IsNullOrEmpty(
expression );
return result;
}

public static string ToFormat(
this string expression, params object[] args )
{
string result = String.Format(
expression, args );
return result;
}

public static bool IsValidEmailAddress(
this string expression )
{
bool result = BaseRegexHelper.IsValid(
expression, emailRegex );
return result;
}

public static bool IsValidGuid(
this string expression )
{
bool result = BaseRegexHelper.IsValid(
expression, guidRegex );
return result;
}

The latter two functions call this method:

public static bool IsValid(
string input, string pattern )
{
bool isValid = false;

if( input != null )
{
string trimmedExpression =
input.Trim();

if( trimmedExpression.Length > 0 )
{
Regex regexGuid = new Regex(
pattern, RegexOptions.IgnoreCase );
isValid = regexGuid.IsMatch(
trimmedExpression );
}
}

return isValid;
}