Complex import/export with EPiServer
The import/export functionality in EPiServer is great. Often, exporting content from the source site and importing it just as it is to the target site is exactly what you need. Simple and easy! If the exported pagetypes do not exist in the target site, you’re able to bring these along as well. Great – most of the time… But sometimes you have special needs.
What if the two sites are very different, and both the source site and the target site have a pagetype called Article? You wouldn’t like to clutter up the target site with a bunch of extra properties from the imported pages, would you? And maybe you’d even like to be able to distinguish the imported pages from the other pages in the target site later on? Also, what if the pagetype you wish to export contains a whole lot of properties, but you’re only interested in getting a few properties like Heading, MainIntro and MainBody?
At first it seemed that I’d not be able to do this, or at least not without a lot of coding. Nothing wrong with coding, of course, but it’s often better to look for built-in possibilities first.
Here’s how I solved this:
- Copy pagetype Article to ImportedArticle
This is a functionality I almost never use (especially not after PageTypeBuilder came along), I seldom touch pagetypes in the “manual” old-fashioned way at all… But boy was I glad this functionality exists! I could obviously have made a totally new pagetype from admin mode, but in this case there were quite a few properties I wanted to include, and this seemed a faster way to get what I wanted.
- Deleted all properties of ImportedArticle not needed in the target site.
- Changed properties implemented with custom properties on the source side to PropertyLongString, thus eliminating the need for implementing the same custom properties on the target site.
- Properties on tabs only existing in the source site were moved to the Information tab.
- Copy pages to export to a new node
In the source site EPiServer tree, I created a new node called ForExport. Then I copied the articles I wanted to export there.
- Convert Pages
Finally I was ready for the main thing: I converted all the pages under ForExport from Article to ImportedArticle. Because all the properties in the two pagetypes had the same names, EPiServer defaulted to copying the properties I wanted and discarding the rest. Perfect!
With all the pages under ForExport converted to ImportedArticle, I could now use the normal export/import functionality to move these pages to the target site (I included the pagetype in the export).
Deleting the ForExport node and everything below it, leaving the target site as it was before I started (except for the new pagetype I have introduced).
Thanks to the EPiServer World community for great help on this issue: