Monthly Archives: January 2014

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!