Orchard CMS provides a nice module to import and export content items. You just need to enable the module called “Import Export”. This will add a menu item in the left navigation sidebar. There you can export all content items of given types. This will create an XML file containing all exported content items. It also provides an import function where you can choose an exported XML file and have it imported.
In Orchard CMS cloning is using the same infrastructure as import/export. So please first read my previous post about cloning content items in Orchard CMS.
Once you’ve added the Importing and the Exporting methods to your driver, you might see that the export file looks like this:
<!--Exported from Orchard-->
<Orchard>
<Recipe>
<Name>Generated by Orchard.ImportExport</Name>
<Author>admin</Author>
<ExportUtc>2014-04-19T14:28:24.7757008Z</ExportUtc>
</Recipe>
<Data>
<MyCustomType Id="" Status="Draft">
<CommonPart Owner="/User.UserName=admin" CreatedUtc="2014-04-17T09:23:30Z" ModifiedUtc="2014-04-17T09:23:30Z" />
<MyCustomTypePart Name="My name is..." />
</MyCustomType>
</Data>
</Orchard>
And when you import this, nothing happens (and the log files contain no error). If it is the case, you have the same problem I had and there is an easy fix.
The problem is that the export file contains an empty ID for all content items. Actually you should have an ID in there starting with /Identifier= and followed by a unique ID. In order to fix it, you need to add an IdentityPart to your content type. Here’s what the Orchard documentation says about the IdentityPart:
The Identity part is useful to provide a unique identity to a content item that doesn’t have a natural one. For example, pages are naturally identified by their relative URL within the site, or users by their user name, but widgets have no such natural identity. In order to enable importing and exporting of those items, the identity part can be added. It creates GUIDs that are used as a unique identity that can reliably be exchanged between instances of Orchard.
So you just need to add this part to your content item. You can either add it in the Admin UI or add an Update method to your Migrations.cs file e.g.:
[UsedImplicitly]
public int UpdateFrom19()
{
ContentDefinitionManager.AlterTypeDefinition("MyCustomType", cfg => cfg.WithPart("IdentityPart"));
return 20;
}
Now the export file will look like this:
<!--Exported from Orchard-->
<Orchard>
<Recipe>
<Name>Generated by Orchard.ImportExport</Name>
<Author>admin</Author>
<ExportUtc>2014-04-19T14:47:34.3426219Z</ExportUtc>
</Recipe>
<Data>
<MyCustomType Id="/Identifier=defe165123124b20a7fcb35e66873fbf" Status="Draft">
<IdentityPart Identifier="defe165123124b20a7fcb35e66873fbf" />
<CommonPart Owner="/User.UserName=admin" CreatedUtc="2014-04-17T09:23:30Z" ModifiedUtc="2014-04-17T09:23:30Z" />
<MyCustomTypePart Name="My name is..." />
</MyCustomType>
</Data>
</Orchard>
And the import will work…
Just what i was trying to figure out. Thank you.
Thanks for explaining this, I’m going to use it for a client’s website I’m working on, trying to transfer blog post pages from Orchard CMS to WordPress.