Why use Anti-Package functionality with Sitecore Rocks?

I wanted to gain an understanding of utilizing the Anti-Package feature of Sitecore Rocks not only the creation process for use as a backup, but also I wanted to verify what happened when I restored with the anti-package in the event just to verify what was taking place.

I started by taking a look at Trevor Campbell’s post on the creation of Anti-Packages here: https://www.sitecore.net/nl-be/learn/blogs/technical-blogs/trevor-campbell/posts/2013/02/28-days-of-sitecore-rocks-package-management-part-1.aspx.  Since, the creation process is pretty well documented, that will not be covered here.

I created a package using Sitecore Rocks and named it MyPackage.

The following items were added:

Items In Package

Items In Package

The following files were added:

Files In Package

Files In Package

The following files were created in a folder I specified:

Created Files

Created Files

Now, that I have my package created I create the anti-package using the process Trevor described in his post.  Take a look at the information at what the creation of the Anti-Package does:

Anti Package Information

Anti Package Information

I added some basic content to the Sample Item using Sitecore Rocks and saved the item as seen below:

Content Added To Sample Item

Content Added To Sample Item

Now, when I install the Anti-Package the Sample Item gets reverted back to its original state as seen below:

Sample Item Original

Sample Item Original

So, I couldn’t help but ponder the question, what is the point of an anti-package when you can make a normal package and re-install it and it should do the same thing right?  As a matter of fact, if I look into the .zip files for my MyPackage.zip and MyPackage.anti.zip they are the exact same.

I believe the benefit lies with using the Anti-Package as a backup strategy particularly in module development for Sitecore.  I think it’s a great habit to get into when working on a module that is continually being updated to create Anti-Packages as you are putting out updates.  The benefit of the anti package is the naming convention (anti.zip) and in Sitecore Rocks the Anti-Package will have its own area for designated Anti-Packages, which could be seen as backups that can be restored at any time. This simple strategy allows you to be able to rollback to most recent release of your module.  For example Excel Transfer Utility Version 1.0, when you are putting together the updated package for 1.0.1, which may contain bug fixes.

Overall, Anti-Packages are beneficial in my opinion.  Not only with Sitecore module development, but as a best practice to have a backup of any important packages you may need to revert back to over time.  Happy coding!

 

 

SEO Toolkit Endless Analyzing Bug

I came across this bug for the second time now and decided to post the resolution so that it may help other developers save some time before turning to Sitecore Support.

Bug:

After installing the SEO Toolkit module when you click on the Search Engine Optimization button in the Desktop, a new window opens up and starts loading the home page.  However, when analyzing that page, or any other for that matter, the “Analyzing page…” continues to spin in the upper right hand corner and never returns any data in the tabs in the very bottom of the web page.

I encountered this bug in these versions:

  • Sitecore Version: 6.6.0 rev. 130111 using SEO Toolkit Version: 1.3.0 rev. 120613
  • Sitecore Version: 6.5.0 rev. 120706 using SEO Toolkit Version: 1.3.0 rev. 110530

Resolution:

  1. Save the image below to your local hard drive (“delete.png”) file and place it in the “\Website\seotoolkit” folder.
    delete.png
  2. Modify the “Website\seotoolkit\client\link.js” file:
Replace this line:
overlay.innerHTML = '<img src="' + seo.page.baseUrl + linkDeleteImageUrl + '" />';
With this one:
overlay.innerHTML = '<img src="' + seo.page.baseUrl + "/seotoolkit/delete.png" + '" />';

This should fix the issue and any page you go to should now take a little bit of time to analyze the page and render data at the bottom of the web page.  Happy coding!

Sorting Template Sections in Sitecore

Here is a little nugget for those Sitecore enthusiasts who want the ability to sort the sections in a content item.  For years I didn’t know about this as a Sitecore Developer so if this helps just one person I have done my job to pass on this helpful knowledge.  Kudos to the guys at Active Commerce for showing me when I went through Active Commerce Certification training.  Active Commerce is a fantastic add-on to Sitecore for E-Commerce functionality and I highly recommend for businesses with lots of products that need an online storefront.  You can find out more about Active Commerce at their website http://www.activecommerce.com.

So let’s just say you have a Content Page template that has the following sections:

  • Page Data
  • Meta Data

I would like the Page Data section to come before the Meta Data section when the template is used to create a new item.  Below is what my template structure looks like:

Template Structure

Template Structure

The Content Page has the PageBase template selected as the Base Template.  The PageBase template has the _pageBase and _metaBase templates selected as the Base Templates.  Both _pageBase and _metaBase templates have the Standard template selected as the Base Template.

The following template sections are selected in this order on the PageBase template __Base template TreeView:

  • _pageBase
  • _metaBase

Being that they are selected in this order you would think that they should show up in the Content item sorted in this manner since the TreeView allows you to sort them.  However, below is what the __Standard Values for the Content Page displays:

Template Sections Order

Template Sections Order

Here is the solution to get the template sections in the order you wish.  In order to sort the sections you must set the Sortorder in the the Template Sections items.  In this case, there are 2 sections; Page Data and Meta Data as seen below:

Template Section

Template Section

The section sorting order is sorted alphabetically unless the sortorder is specifically stated using the Sortorder field in the Template Section items.  Hence, the reason Meta Data comes before Page Data (refer to Template Sections Order).  By default, the Sortorder field is set to 100 as seen below:

Sortorder Field

Sortorder Field

Depending on how many sections you want to sort you can increment these numbers to achieve the desired result.  For example, if I had 4 sections I would just add 100 to the other Sortorder fields in the respective Template Section items.  Since I have 2 sections I only need to set the other Meta Data Sortorder field to 200 and it will place that section underneath the Page Data section as seen below:

Section Sorting Order Achieved

Section Sorting Order Achieved

This knowledge can be used to help out the organization of your templates and give power to Content Editors to access the most relevant sections of items first when there are many sections in the an item.  Happy coding!

How to Uninstall a Package or Module from Sitecore

There are times when I have been asked to uninstall a package, Sitecore Marketplace module (package), or even an internal Sitecore module (package) that your company has developed for a client.  In the event you are not aware of this fact, there is not a rollback feature on packages in an out of the box Sitecore installation.  Hence, if you want to rollback a package you basically need backups of the files and the databases and can then perform a restore procedure with them. If you don’t have the time for backups or forgot to make backups before installing the package below are the basic steps to uninstall a package manually:

Basics for uninstalling a package:

Download the original package/module again so you can analyze the contents.  It should be downloaded as a .zip file.

Extract the .zip file and you will see a package.zip file.  Extract the contents of that as well and you will see the contents of the package as such:

Package Contents

Start with the manual deletion of the items first. Please keep in mind that every module may be different so prior planning on what items or fields need to stay is dependent upon client needs and the architecture.  Just make sure that when you delete items that they truly need to be deleted based on your clients needs. In my case, I moved a couple of fields to another template so the data and field ID’s remained after I uninstalled the module.

Drill down into the items folder and you will see where the items are. These will be the items that you need to manually delete.  For instance, in my example I need to delete the following: \items\core\sitecore\content\Applications\WebEdit\Edit Frame Buttons\Metadata\Edit Metadata\{E43B0BB5-2158-4880-AC16-ABE74593B556}

The GUID is the item and you can find it easily by using search in the Content Editor as such:

Item Search

Sometimes it’s best to open up another Sitecore admin instance for that same version or similar to compare the content items to just to make sure you are not deleting an item that was already in place before the package or module was installed.  It’s always a good reference. Also, if you are deleting from the master database it’s best to delete in this order:

  1. content
  2. layouts
  3. system
  4. templates

This will give you minimal to no linking issues as you manually delete the installed items.

After deleting the items from the core and master database, I perform a full republish just to ensure nothing is missed from the web database and everything is synced in entirety. Next, I rebuild the Link databases just to make sure that all links are correctly pointed.  You can Rebuild the Link Database in the Control Panel of the Desktop:

Rebuild the Link Database in Control Panel

Next, are the manual deletion of the files.  In my case there is only a .config file I need to delete in the \files\App_Config\Include directory and a .dll in the \files\bin directory.

The .config file I simply deleted so that the processor does not show up in the Web.config at runtime. However, I had to delete a reference to the .dll in a few projects from within the solution and this is where some refactoring may need to take place that was using that .dll.  In my case, there is some dependent code that was referencing the .dll used in the module so I had to refactor, delete code, rebuild, and publish back out to my website folder to test and make sure everything is working as it should.  After my testing, I am good to go!

That is all there is to it to uninstall a package or Sitecore module.  Just take your time and pay attention to detail.  I hope these steps can help you.  Happy coding!

Monitoring a Sitecore package install in real time

When you install a package into a Sitecore instance you have no idea what is going on behind the scenes because all you see is a progress bar.  If the package fails then it will let you know but don’t get to see what is happening.  And sometimes if it is a large package you don’t really know if there was an error and if the package is going to be installed, has installed, or is trying to be installed so you wait and wait but don’t want to end the installation because then you will have to start over but you really don’t know.  Well…now you can know and it’s very simple.  This will help you to know in real-time what errors are happening during the install and what items are being installed.

You can monitor any Windows log file in real time by using Windows PowerShell.  I am not a command line type of guy but there is only one command you need to know and I will explain the steps you need to take:

  1. Open up Windows PowerShell on your machine
  2. Get the file path and file name with extension to most recent Sitecore log file
  3. Type in:
    type -wait PATHTOFILEANDFILENAMEWITHEXTENSION

    Example:

    // Use if path has no spaces in path folder names
    type -wait C:\inetpub\wwwroot\SitecoreSandbox\Data\logs\log.20140812.txt
    
    // Use if path has spaces in the path folder names
    type -wait "C:\inetpub\wwwroot\Sitecore Sandbox\Data\logs\log.20140812.txt"

    Then press Enter.

    Windows PowerShell Command

    Windows PowerShell Command

  4. Now install your package using the Installation Wizard

You will see the log now being updated in real-time as the package installs.

In my most recent install this saved me a lot of time troubleshooting because I was able to see why my package was failing in real-time because of MemoryMonitor thresholds, InvalidItemNameChars, and ItemNameValidation.  Once I adjusted these values in the Web.config my package was installed in my local development environment.  Now I can change them back and keep coding like a ninja.  Happy coding!

Using field item id to render field contents in Sitecore

Did you know that you can use the field item id for use with the FieldRenderer server control in the FieldName attribute?  For instance, take a look at this sample template item:

Sample Template

Sample Template where “Single Line Text Field” item id is {D2775315-00DC-4CF4-8B68-E9748127D188}

<sc:FieldRenderer ID=”frSingleLineText” runat=”server” FieldName=”{D2775315-00DC-4CF4-8B68-E9748127D188}” Item=”<%# Sitecore.Context.Item %>”></sc:FieldRenderer>

Why would you do this? Well, instead of having to memorize field name you can simply use the field item id.  But a much better reason is because if anyone ever changes the field name then the FieldRenderer will not work whereas if you put the field item id it will still continue to work regardless of how many times someone changes the field name.  You want to stay away from using Field names altogether in your code and stick to using id’s wherever possible.  This is why GlassMapper and other ORM tools are great because they do much of the same similar thing by wrapping up the fields so you can access the template as an object and the fields as a property.  However, sometimes you have to use the traditional Sitecore API to get things done and this is one way to keep code robust.

You can also do this as well in the code behind for a sample Literal control that is going to render the Single Line Text Field contents:

litSingleLineText.Text = myItem[“{D2775315-00DC-4CF4-8B68-E9748127D188}”];

This would require a compile in the solution though.  A better solution is to add the item in the HTML markup and you have a tag that is completely in the presentation and doesn’t need to be compiled when changed.

<sc:FieldRenderer ID=”frSingleLineText” runat=”server” FieldName=”{D2775315-00DC-4CF4-8B68-E9748127D188}” Item=”<%# Sitecore.Context.Item %>”></sc:FieldRenderer>

What type of Sitecore license do we have?

Ever wonder this question?  Maybe you have inherited the Sitecore development work or you are a consultant and now taking over the Sitecore development work and need to know what the client has got in their licensing agreement with Sitecore.

Take a look at the “About Sitecore” area in the Desktop area as seen below:

About Sitecore

About Sitecore in Desktop View

Once you click on the “About Sitecore” link you will see the licensing as seen below:

Licensing for Sitecore

Licensing for Sitecore

 

Top Features of Sitecore Rocks

Over the past few months I have been spending more time getting familiar with useful features in Sitecore Rocks in an effort to boost productivity.  Below are some of my favorite features.  I will not be covering how to set up Sitecore Rocks within Visual Studio.  This link will take you to the setup of Sitecore Rocks within Visual Studio: http://vsplugins.sitecore.net/default.aspx.

Cache Management

When developing within Sitecore a lot of the times we need to clear the caches in order to see changes.  Instead of using [local]/sitecore/admin/cache.aspx to clear the caches, Sitecore Rocks has all the caches accessible in Visual Studio.  Here you can clear specific caches or even clear all caches without leaving Visual Studio.  Simply right-click on the caches area and you will see the options.

Cache Management

Cache Management

Quick Item Creation for Testing of Repeated Items

Sitecore developers know all too well that when developing we are going to be using databound controls such as ASP.NET ListView server controls to display repeated items from the content tree.  Instead of duplicating one item at a time using the Sitecore Content Editor we can create all these items at once to do some testing, which will save us Sitecore developers a bit of time just to see if our code is functioning as intended.  All you need to do is open up Sitecore Explorer and click on the item where you want to add the items as children, then click Ctrl-A. This will bring up the “Add New Item” dialog box:

Add New Items Dialog Box

Add New Items Dialog Box

Now, you simply select the template and how many items you want to create.  In the above example I select the Repeat template and add 3 more items.  Now, I have 4 “Repeat Template” items in the content tree as children of the item selected initially:

Addition of Multiple Items At Once

Addition of Multiple Items At Once

Creation of Items from Files

Maneuvering between Sitecore Content Editor and Visual Studio can be a pain when you want to create a layout or sublayout and then tie it to the layout or sublayout item in the content tree.  Sitecore Rocks helps us Sitecore developers by giving us the ability to create items from the Web User Controls or Web Forms within Visual Studio.  Below is an example of a basic Visual Studio Sitecore solution:

Basic Sitecore Solution

Basic Sitecore Solution

Using the above example, I want to create a sublayout item in the content tree using the “Sandbox Sublayout.ascx”  web user control.  To do this I simply right-click on the web user control and hover over Sitecore where I see another window open up and I click on “Create Items From Files…” (if this option is not available you will need to connect the solution to the databases by right-clicking on the solution and then hovering over Sitecore, then click “Connect…”).  Now you will see the Create Items from Files dialog box:

Create Items From Files Dialog Box

Create Items From Files Dialog Box

Now we simply select where we want the item created.  In the above example I select the “layouts\sublayouts\Sandbox” folder in the Master database then click on OK.  Now I get the Log dialog box that shows me that the item was created:

Item Created in Content Tree

Item Created in Content Tree

Now if I refresh the content tree in Sitecore Explorer I can see the new item I created from the file in Visual Studio:

Item Created From File

Item Created From File Now in Content Tree

If I view the sublayout item I can see the path is correct to where my file is located in my basic Visual Studio Sitecore solution:

Sublayout Details

Sublayout Details with Correct Path to File

Publishing Items and Dependencies

Another useful feature of Sitecore Rocks is the ability to publish items and their dependencies.  This comes in handy when you may have don’t may have forgotten what was associated with the item such as the layouts, sublayouts, template, etc.  So instead of having to remember what was associated with the item, Sitecore Rocks will take care of that for you and publish the item AND it’s dependencies.  For this example I have created an item in the content tree called Sample Item which is using the Sample Item template that comes out of the box with a standard Sitecore installation.  In the Layout Details, I am using the Sample Layout, also out of the box with a standard Sitecore installation, and then set the Sandbox Sublayout as the rendering using the Content placeholder:

Sample Item to Publish with Dependencies

Sample Item to Publish with Dependencies

Sample Item Layout Details

Sample Item Layout Details

Now, if I right-click on the “Sample Item” in the content tree and hover over “Tools”, then hover over “Publishing”, I will then see the “Publish Item and Dependencies…” option.  When clicked upon we get the Publish dialog box with the dependencies that will we can select to publish.  Notice the Sample Item, Sample Layout, Sandbox Sublayout, and Sample Item template:

Publish Items with Dependencies Dialog Box

Publish Items with Dependencies Dialog Box

Now, when we click on the OK button all the dependent items will be published and this relieves us from some of the guesswork involved in our day to day Sitecore development.

 

Excel Transfer Utility for Sitecore

During my tenure working with Sitecore I have had a few clients that wanted the ability to import data into Sitecore items from an Excel spreadsheet as well as export Sitecore item/s data to an excel spreadsheet.  I was unable to find a shared source module that would do this simple transfer easily so I ended up having to build a utility for every client.  I finally decided to build a Shared Source Module for this basic task, http://marketplace.sitecore.net/en/Modules/Excel_Transfer_Utility.aspx.  The Excel Transfer Utility is a simple module that will give you the ability to import data from an Excel spreadsheet that are converted into newly created Sitecore items in the content tree. Also, the export functionality will export the data from a Sitecore item (single item or all children items) data to a .csv file for use with an Excel spreadsheet. This post will detail out the utility and how to use it.

Import

The Import functionality is intended to be used given the following requirements:

  • Microsoft Excel 97-2003 files only (Newer Excel files must be converted to 97-2003 before uploading)
  • Headers are in the first row of the spreadsheet
  • Item name is the first column of the spreadsheet

In this example we are going to import a simple spreadsheet into a folder item called “Excel Transfer Folder” in the Sitecore content tree as seen below:

Import Folder

Import Folder with ID: {A91FD891-C477-45F5-B20A-7CFA7F8B53E5}

We will also need to know the template ID of the template we want to use for the imported items. Below is the template we will use:

Sample Template

Sample Template with ID: {D2775315-00DC-4CF4-8B68-E9748127D188}

Below is an example with a simple spreadsheet with 3 fields (Single Line Text Field, Checkbox Field, and MultiList Field) and data for those fields:

Sample Excel Spreadsheet

Spreadsheet with 3 fields and sample data.

Now that we have a spreadsheet with data ready to import we simply open up the Excel Transfer Utility from the Sitecore admin area using the Desktop view:

Excel Transfer Utility Shortcut

Excel Transfer Utility Shortcut in Applications

Once clicked on the application will open up in a new window:

Excel Transfer Utility Home

Excel Transfer Utility Home Screen

Click the Import button and you will see the following options. Choose your file and click the Upload button:

File Selection for Import

File Selection for Import

Once the file is uploaded the sheet names in the Excel spreadsheet will be in the DropDownList.  Select the sheet with the data to import. Next, enter the template ID to use for the imported items and click the Next button:

Sheet & Template Selection

Sheet & Template Selection

Now select the Header name to be used for the item names.  Then select the Template Item Fields that are to be mapped with each of the spreadsheet fields (picked up from the Header in the first column). Next, enter the parent item ID where all items in the spreadsheet will be imported to as children and click Import:

Mapping & Item Selections

Mapping & Item Selections

If the import was a success then you will see the success screen as seen below:

Import Success Message

Import Success Message

Now when we take a look at the “Excel Transfer Folder” in the Sitecore content tree we can see the imported items, in this case since there is only one one row of data, there is only one item that was created:

Imported Items

Imported Items

When we look in the item at the field data we can see the data was imported into the fields for the item:

Imported Item Field Data

Imported Item Field Data

Text is imported as text, values for checkboxes are either “true” or “false” in the spreadsheet not 0 or 1, and lastly multilist values in the spreadsheet must be a pipe separated list of GUID’s.  Please note: mapping data to incorrect fields will product unexpected results such as a text field to a checkbox field in a Sitecore item.

Export

In this example we will export the item created in the Import example to a .csv file for use with Microsoft Excel:

Imported Items

Item to Export

Again, we simply open up the Excel Transfer Utility from the Sitecore admin area using the Desktop view and click on the Export button this time. Now, we select multiple items because I want to select all the items in the Excel Transfer Folder, which is one, but if there were several items all of them would get exported:

Initial Export Selection

Initial Export Selection

Next, we either insert the item ID (if single item) or the parent item ID (if multiple items) and the children items of the parent will be exported:

Multiple Items Export

Multiple Items Export

Once we enter the ID we click on the Export button and the items are exported to a .csv file:

Export Success with File Path

Export Success with File Path

Copy the file path into Windows Explorer and the file should open up in Microsoft Excel as seen below:

Exported Items

Exported Items

If you have any questions or ideas on how to make to the tool better please comment.  Thanks and happy coding!

Sitecore Query with MultiList and multiple sites

Have you ever been in the situation where you would like to point the “Source” field of template field to an item that will be used with a List Type field such as the MultiList, but you wanted that field to be pointed to a folder in the site the user is currently visiting?

Multiple Sites

Multiple sites in Sitecore

One reason you may want to set a “Source” field to an item in the context site may be because the item you are creating is intended to be used with the DMS (Digital Marketing System) for personalization, A/B, and multivariate testing.  We can get solid results in those areas with a data source component-based architecture where components can be conditionally rendered across pages in the same site or even across all sites in the Sitecore instance.

Anyways, an easy way of setting up a “Source” for a MultiList is simply just to point the “Source” field to the /sitecore/content/ item and let the user drill down into the folders to get to the folder they want.  However, depending on how many sites the Sitecore instance has, in addition to the amount of content, this will turn out in most cases to be a bad user experience, and could lead to error where the user may accidentally choose items from another site.

A better solution is to use Sitecore query to set the “Source” field in the template field.  If you are not familiar with the Sitecore Query or Sitecore Fast Query, I would recommend visiting the Sitecore Developer Network and reading up on it.  The most recent Sitecore Query documentation I found was here: Sitecore Fast Query documenation.  You will find it’s not that difficult to grasp and you can start using it right away once you see how the useful the queries can be in your day to day Sitecore development.  In addition, Sitecore was kind enough to provide us Developers with the XPath Builder available in the Developer Center application via Tools –> XPath Builder.  Below is a screen shot of the XPath Builder application:

XPath Builder

XPath Builder application in Sitecore Developer Center

All you need to do is set the Context Node to the item you want to start with for the query, build your XPath expression in the next field, and hit the Evaluate button and you will see the results in the Result field.  Using this tool you don’t have to guess if your query is correct when you insert it in the “Source” field.  Build it here, test it, then just copy and paste it into the “Source” field (along with “query:” added to the beginning of the query).  That simple!

In one of my projects, I needed to point to a data folder in the context site that had the items I needed, as children, that I wanted to show in my MultiList.  In the example, below I wanted to set the “Source” field in my ScriptSelectionItem to the ScriptItems folder for the context site so the user would only see the ScriptItems created for that site only and the user can just select the ones they want.  Again, we want to get away from drilling down into the site specific folders and then making selections to create a better experience for the user and reduce errors.

Sitecore template

We will set the Source field with the Sitecore query built and tested in XPath Builder

Below is my query that I built and tested in the XPath Builder to start with the ancestor-or-self of the context item and then match up the template ids of the items once the initial ancestor-or-self item is established:

./ancestor-or-self::*[@@templateid='SITE TEMPLATE ID']//*[@@templateid='DATA TEMPLATE ID']//*[@@templateid='SCRIPTS TEMPLATE ID']//*[@@templateid='SCRIPTITEMS TEMPLATE ID']/*

When you add the query to a “Source” field you need to add the “query:” to the front of the query as such:

query:./ancestor-or-self::*[@@templateid='SITE TEMPLATE ID']//*[@@templateid='DATA TEMPLATE ID']//*[@@templateid='SCRIPTS TEMPLATE ID']//*[@@templateid='SCRIPTITEMS TEMPLATE ID']/*

Now, when I add the query to the “Source” field in my ScriptsSelectionItem template field and open the ScriptSelectionItem in the Content tree, I now see that the MultiList field points to only the items in the context site for the user.  I have not gotten this to work with the DropTree List Type but the MultiList has worked just fine for my purposes.  Happy coding!

The ScriptSelectionItemSiteB should only point to the 1 script in the ScriptItems folder

The ScriptSelectionItemSiteB should only point to the 1 script in the ScriptItems folder

Notice only the 1 script is available for Site B

Notice only the 1 script is available for Site B

Now for Site A:

The ScriptSelectionItemSiteA should only point to the 3 scripts in the ScriptItems folder

The ScriptSelectionItemSiteA should only point to the 3 scripts in the ScriptItems folder

Notice the 3 scripts are available for Site A

Notice the 3 scripts are available for Site A