For those looking at upgrading from Sitecore 6.x to 7.x beware of a subtle advancement that is very beneficial in most situations but a major issue in another.
Scenario #1: A client is migrating from an existing CMS and pulls the content from the existing cms into Sitecore on a regular basis during migration to reduce the size of the outage windows for Clients.
Scenario #2: A client injects data into Sitecore from an external system via clearing all the nodes under a certain node in sitecore and then re-imports the content items.
In both these scenarios the Guid would chance for the content item but the path would remain the same.
In Sitecore 6.6, this would work fine as the DataSource property of the sublayout stored the Item Path.
In Sitecore 7.0, a cool advancement was introduced that allowed you to move content around and it would automap the DataSoure much like it does with content links. Nice feature but in the above scenarios it will break existing SubLayouts.
Workaround: This is not ideal but if you place text in front of the item path eg. "ITEM_PATH:" then sitecore cannot resolve the sitecore path so it will keep the string there. Then in the sublayout when you grab the DataSource you look for that string and remove it before calling GetItem. Here is some sample code:
if (string.IsNullOrEmpty(subLayout.DataSource))
return Sitecore.Context.Item;
string dataSource = subLayout.DataSource;
Item dataSourceItem = null;
if (dataSource.StartsWith("ITEM_PATH:"))
{
dataSource = dataSource.Substring(10);
}
if (Sitecore.Context.Database.GetItem(dataSource) != null)
{
dataSourceItem = Sitecore.Context.Database.GetItem(dataSource) ??
Sitecore.Context.ContentDatabase.GetItem(dataSource);
Log.Info("CurrentContextBased On Data Source (" + dataSource + ")", this);
}
Alternatively someone could override part of the mechanism to handle "ITEM_PATH:" much like Sitecore itself does currently with "query:" If someone has created one, and is willing to share it in MarketPlace for others to use, let me know and I will reference it here for others to access.