Sitecore Content Importing: Use a CSV file to create or edit Sitecore content

If you Google “Import Sitecore content”, you can quickly see that importing content is a popular topic, and there is not one standard recommended way to do so. Developers will often write custom import tools to allow users to create items by uploading a CSV file. With the latest addition to the Content Export Tool (now aptly re-named the Content Export/Import Tool), you can now easily edit or create Sitecore content without any greater effort than installing a Sitecore package, with a tool that is easy for both technical and non-technical people to use.

How do you use it?

The Import feature has two options: Create and Edit. Create will create new items under the path specified, using a specified template and name. Edit will edit items at the path specified to update their field values with the values given in the CSV.

Example Create file:

createexample
Example Create file with Item Path, Template, and Name (required) and two fields

Example Edit file:

editexample
Example Edit file with Item Path (required) and two fields

Specify the Item Path (of the current item to Edit or of the parent item to Create), as well as Template and Name if creating items, and all fields you wish to populate. Field names must be exact (though not case sensitive). Item paths and Templates can be either full Sitecore paths or Guid IDs.

Fields that do not exist for an item will be skipped, but will not cause an error. This means that you can Import items of different template types at once and edit fields even if those fields do not exist on all of the templates. If a field is not included in the CSV, it will not be affected, but if a field is included and the value is blank, then that field on the Sitecore item will be empty.

To run the import, simply upload your CSV file and then click either Create Items of Edit Items. By default, Create Items will not create duplicate items (i.e. an item with the same path and template), but you can uncheck the box if you want duplicates to be allowed.

Import.PNG

The diagnostic output will inform you of all fields or lines that were skipped once the import is complete.

How does it work?

The tool parses the CSV file (using some amazingly helpful code borrowed from Josh Close’s CsvHelper). For each line, it gets the item at the path specified, and either edits that item, or if in Create mode, creates a new item under that item and then edits the new item. For each field in the CSV, if that field exists on the item, the field value is set to the value in the CSV.

Features and Abilities:

  • You can create or edit items of different types all at the same time; if a field does not exist for one of the items, it just skips that field
  • Sequential Creation: Since you can create different types of items at the same time, you can create a new item and then more new items beneath that item

cascadingcreation

  • It can handle any field types, including links, images, reference fields, multilists, checkboxes, date fields, and of course string fields.
    • For multilists or other field types that contain multiple Sitecore items, the items should be listed as sitecore paths or IDs separated by semicolon
      • example:
        /sitecore/content/home/tax/red;/sitecore/content/home/tax/blue
  • No  installation steps necessary; simply install the Sitecore package and go!

Language Versions:

By default, the import process will create or edit items in the default Sitecore language. However, you can specify the language by adding a Language column and providing the language name you want to use. In the Tips, you can see a list of all the valid language names.

language tips.PNG

When creating items, the items will be created in the language specified or the default language.

When editing items, the item will be edited in the language specified, and if a language version does not exist in the specified language, a version will be created. If you wish to create new language versions of existing items, use the Edit feature rather than the Create feature; Create will not add a new item if the item already exists, even if a language version does not currently exist.

Security

Sitecore read/write permissions for the current user apply to the Edit and Create features. If a user only has read access to an item, if they attempt to modify it or create a child item using the Import feature, they will receive an error message informing them that they do not have permission.

In conclusion…

The best part about the tool is that because it is built in with the Content Export Tool, you can use the Export feature to do all the heavy lifting for you in creating your CSV import file. If you need to modify a few fields on a bunch of Sitecore items, you can use Export to download a CSV file with all the item paths and fields you need, edit the field values in the CSV file, and then import that file.

The tool should be available within the next few weeks in the Sitecore Marketplace, but can also download the latest package from Github if you want to try it sooner. Stay tuned and follow me on Twitter to be notified when the tool becomes available. You can download the current version of the Content Export Tool here.

The tool has been tested in Sitecore 6.5 and 8.2, and 9.0

Author: ericastockwellalpert

.NET Developer and Sitecore MVP 2019-2020

2 thoughts on “Sitecore Content Importing: Use a CSV file to create or edit Sitecore content”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s