asp.net-mvcorchardcmsorchardcms-1.6

Custom part properties missing in export Orchard 1.6


I have a problem with the import export module in Orchard 1.6:
I want to export a custom type with a part that has a property in it. The export XML contains data from TitlePart, CommonPart, BodyPart and AutoroutePart, however the data from my own part is not there.

Is there anything I should do like implementing an interface or overriding something on my part so that it is contained within the export XML? What are (if any) the extension points of the export module? I have the source of the module but cannot find it.

The module.txt of the particular export module is:
Name: Import Export
Path: ImportExport
AntiForgery: enabled
Author: The Orchard Team
Website: http://orchardproject.net
Version: 1.6
OrchardVersion: 1.4
Description: Provides content item data import and export capability.
FeatureDescription: Imports and exports content item data
Category: Content

Thanks in advance :)


Solution

  • You need to override theExporting/Importing methods in your content part driver. Here is a simple example from the Orchard.Core.Title.Driver.TitlePartDriver:

    protected override void Importing(TitlePart part, ImportContentContext context) {
        var title = context.Attribute(part.PartDefinition.Name, "Title");
        if (title != null) {
            part.Title = title;
        }
    }
    
    protected override void Exporting(TitlePart part, ExportContentContext context) {
        context.Element(part.PartDefinition.Name).SetAttributeValue("Title", part.Title);
    }
    

    The ImportExportContext class provides access to the underlying XML structure used to generate the output document, so if you are used to using System.Xml.Linq, XDocument etc then it will all seem familiar.

    There are some other examples of usage in Orchard.Core.Common.Drivers.CommonPartDriver, Orchard.Users.Drivers.UserPartDriver, and Orchard.Comments.Drivers.CommentPartDriver.