Kentico CMS 7.0 Developer's Guide

Import

Import

Previous topic Next topic Mail us feedback on this topic!  

Import

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example imports a single user object included in a sample APIExample_User.zip import package stored in ~\CMSAPIExamples\Code\Tools\ImportExport\Packages\.

 

private bool ImportObject()

{

  // Create site import settings

  SiteImportSettings settings = new SiteImportSettings(CMSContext.CurrentUser);

 

  // Initialize the settings

   settings.WebsitePath = Server.MapPath("~/");

   settings.SourceFilePath = settings.WebsitePath + "\\CMSAPIExamples\\Code\\Tools\\ImportExport\\Packages\\APIExample_User.zip";

   settings.ImportType = ImportTypeEnum.All;

   settings.LoadDefaultSelection();

 

  // Import

  ImportProvider.ImportObjectsData(settings);

 

  // Delete temporary data

  ImportProvider.DeleteTemporaryFiles(settings, false);

 

  return true;

}

 

The following example imports a complete website included in a sample APIExample_Site.zip import package stored in ~\CMSAPIExamples\Code\Tools\ImportExport\Packages\.

 

private bool ImportSite()

{

  // Prepare the properties

  string websitePath = Server.MapPath("~/");

  string sourceFilePath = websitePath + "\\CMSAPIExamples\\Code\\Tools\\ImportExport\\Packages\\APIExample_Site.zip";

  string siteDisplayName = "My new imported site";

  string siteName = "MyNewImportedSite";

  string siteDomain = "127.0.0.1";

 

  // Ensure there is no site with the set name

  if (SiteInfoProvider.GetSiteInfo(siteName) == null)

   {

      // Import

      ImportProvider.ImportSite(siteName, siteDisplayName, siteDomain, sourceFilePath, websitePath, CMSContext.CurrentUser);

 

      return true;

   }

 

  return false;

}