Using API to export global objects

David Parker asked on June 13, 2014 10:05

Is there a way to use the kentico API to create the same zip files used by the "Export objects" button? I've found API examples for creating "export site" zips, but cant understand how the API is used to generate a global objects zip.

Hopefully you are still support Kentico 7 API as we haven't moved to v8 yet.

Recent Answers


Martin Danko answered on July 15, 2014 10:39

Hello David,

Yes, version 7 is still supported, at the we provide support for Kentico 6, 7 and 8.

Thank you for your reply. You would need to set the setting opject as follows:

settings.ExportType = ExportTypeEnum.All

Here are the available options:

<member name="T:CMS.CMSImportExport.ExportTypeEnum">
            <summary>
            Export type enumeration
            </summary>
        </member>
        <member name="F:CMS.CMSImportExport.ExportTypeEnum.None">
            <summary>
            No objects
            </summary>
        </member>
        <member name="F:CMS.CMSImportExport.ExportTypeEnum.All">
            <summary>
            All objects
            </summary>
        </member>
        <member name="F:CMS.CMSImportExport.ExportTypeEnum.Site">
            <summary>
            Site objects
            </summary>
        </member>
        <member name="F:CMS.CMSImportExport.ExportTypeEnum.Default">
            <summary>
            Default
            </summary>

I believe you will only export site-specific object if you set the property to the following: CMS.CMSImportExport.ExportTypeEnum.Site

Additionally, here are some sample settings just for future reference since the documentation does not include many of these:

try
{
SiteExportSettings settings = new SiteExportSettings(); // Prepare settings for the export

settings.SiteName = "siteName"; // Set site name if site is exported
// settings.SiteId = siteId; // or site id

settings.WebsitePath = "websitePath"; // Optionally set website path (full path or relative)
settings.TargetPath = "targetPath"; // Optionally set target path (full path or relative)
settings.TemporaryFilesPath = "tmpPath"; // Optionally set temporary files path (full path or relative)

settings.ExportType = ExportTypeEnum.All; // Export type (All, None, Default…)
settings.TimeStamp = DateTimeHelper.ZERO_TIME; // Set DateTime for incremental deployment

// Set if files should be exported
settings.CopyFiles = true;
// Set if the exported data sould be packed (for web templates used false)
settings.CreatePackage = true;
// Objects which code name starts with excluded name will not be exported
settings.ExcludedNames = string[] {"test"};

// Ensure objects preselection due to previous settings with all child and related objects
settings.LoadDefaultSelection();

// Ensure only specific object selection with ExportType set to None
// settings.SetObjectsProcessType(ProcessObjectEnum.Selected, SiteObjectType.WEBPART, false);
// settings.SetSelectedObjects(new string[] { "codeName" }, SiteObjectType.WEBPART, false);

// All objects of specified type will be exported
settings.SetObjectsProcessType(ProcessObjectEnum.All, SiteObjectType.INLINECONTROL, false);

// Documents related settings
settings.SetSettings(ImportExportHelper.SETTINGS_DOC_HISTORY, false);
settings.SetSettings(ImportExportHelper.SETTINGS_DOC_ACLS, false);
settings.SetSettings(ImportExportHelper.SETTINGS_DOC_RELATIONSHIPS, false);
settings.SetSettings(ImportExportHelper.SETTINGS_EVENT_ATTENDEES, false);
settings.SetSettings(ImportExportHelper.SETTINGS_BLOG_COMMENTS, false);

// Object type specific settings
settings.SetSettings(ImportExportHelper.SETTINGS_BIZFORM_DATA, false);
settings.SetSettings(ImportExportHelper.SETTINGS_FORUM_POSTS, false);

// Object files and folders
settings.SetSettings(ImportExportHelper.SETTINGS_GLOBAL_FOLDERS, false);
settings.SetSettings(ImportExportHelper.SETTINGS_SITE_FOLDERS, false);
settings.SetSettings(ImportExportHelper.SETTINGS_COPY_ASPX_TEMPLATES_FOLDER, false);

// Export
ExportProvider.ExportObjectsData(settings);
}
catch(Exception ex)
{
// Handle error during export process
}

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.