Category Archives: Did you know…

All the cool things I find out as I go along in my Sitecore development that make say, “Cool, I didn’t know that”.

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

 

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

FieldRenderer and EnclosingTag property

So I was working on a sublayout earlier today and I ran across a piece of HTML that made me say, “Hmmm…, what is the best way to tackle this situation”?  I had the HTML below to work with for the “Page Title” and “Sub Title” fields that were to be simply rendered in a FieldRenderer control.

<h1>My Account <small>Manage your account online</small></h1>

The title “My Account” would always exist but the “Manage your account online” in the <small> element would be optional for the Content Editor to use to display sub-titles.  Well, I am a programmer who likes to leave no markup behind so I quickly remembered the EnclosingTag property of the FieldRenderer that made perfect sense in this situation.  Below is the markup I used to pull in the fields:

<h1>
<sc:FieldRenderer runat="server" FieldName="Page Title" ID="frPageTitle"></sc:FieldRenderer>
<sc:FieldRenderer runat="server" FieldName="Sub Title" ID="frSubtitle" EnclosingTag="small"></sc:FieldRenderer>
</h1>

Instead of leaving the <small> HTML element in the markup on the page if the “Sub Title” field is blank, I used the EnclosingTag property to ensure that if there is a value to render it inside the <small> HTML element. However, if the field is blank then don’t display the <small> HTML element either. Pretty slick when you need it sometimes! Happy coding!

Easy deleting of Sub-Items in Sitecore

Ok, so I have been working in the Sitecore Content Editor for 5 years now and it shows that you learn something new every day.  I needed a quick and easy way to delete a bunch of sub-items.  For the longest time I would go through and delete each item from the list.  If the deleted item had sub-items then I would delete that whole folder with the sub-items as well.  However, what if I just wanted to delete the items that were sub-items but not the actual item itself?  This is where I started looking through the Ribbon for the answer and found it.  Take a look at the given Colors item list:

Colors Item List

All you have to do is click on the parent item, which in this case is the Colors folder item, and then click on the Home tab in the Ribbon, and then click on the Delete drop-down in the Operations chunk.  You will then see the action to “Delete Subitems”, click on the icon and you will get a dialog box that says, “Are you sure you want to delete these 11 items?”  Click OK and voila they are all gone but the parent folder is left behind as seen below.  Easy peezy.  Happy coding!

Colors Item List - No Subitems

Fast and easy sorting in Sitecore

You can easily sort items in the content tree by clicking on the Alt button and then dragging the item where you want it and then letting go.  You will then receive a dialog box that says, “Are you sure you want to move ‘XYZa’ item before ‘XYZb’ item?”  Just click the OK button the item will now be there.  For a quick sort this has saved me time and hopefully it will help you.  Happy coding!