Kentico CMS 6.0 Developer's Guide

Export

Export

Previous topic Next topic Mail us feedback on this topic!  

Export

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 exports the user object imported by the first example on the previous page into a new export package.

 

private bool ExportObject()

{

  // Delete temporary data

  try

   {

      ExportProvider.DeleteTemporaryFiles();

   }

  catch

   {

   }

 

  // Get user

  UserInfo exportedUser = UserInfoProvider.GetUserInfo("MyNewImportedUser");

 

  // Ensure that user exists

  if (exportedUser != null)

   {

      // Prepare the properties

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

      string exportFileName = string.Format("APIExample_User_{0:yyyy-MM-dd_hh-mm}.zip", DateTime.Now);

      string exportFilePath = FileHelper.GetFullPhysicalPath(ImportExportHelper.GetSiteUtilsFolder(), websitePath) + "Export\\" + exportFileName;

 

      // Ensure there is no exported package with the same name

      if (!File.Exists(exportFilePath))

       {

          // Export

          ExportProvider.ExportObject(exportedUser, exportFilePath, websitePath, CMSContext.CurrentUser);

 

          return true;

       }

   }

 

  return false;

}

 

The following example exports the website imported by the first example on the previous page into a new export package.

 

private bool ExportSite()

{

  // Delete temporary data

  try

   {

      ExportProvider.DeleteTemporaryFiles();

   }

  catch

   {

   }

 

  // Prepare the properties

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

  string exportFileName = string.Format("APIExample_Site_{0:yyyy-MM-dd_hh-mm}.zip", DateTime.Now);

  string exportFilePath = FileHelper.GetFullPhysicalPath(ImportExportHelper.GetSiteUtilsFolder(), websitePath) + "Export\\" + exportFileName;

  string siteName = "MyNewImportedSite";

 

  // Ensure that site exists

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

   {

      // Ensure there is no exported package with the same name

      if (!File.Exists(exportFilePath))

       {

          // Export

          ExportProvider.ExportSite(siteName, exportFilePath, websitePath, false, CMSContext.CurrentUser);

 

          return true;

       }

   }

 

  return false;

}