---
title: Import and export
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

## Import

### Importing an object

```csharp

// Creates an object containing the import settings
SiteImportSettings settings = new SiteImportSettings(MembershipContext.AuthenticatedUser);

// Initializes the import settings
settings.SourceFilePath = "Packages\\APIExample_User.zip";
settings.ImportType = ImportTypeEnum.AllNonConflicting;
settings.LoadDefaultSelection();

// Imports the package
ImportProvider.ImportObjectsData(settings);

// Deletes temporary data
ImportProvider.DeleteTemporaryFiles(settings, false);

```

[> Back to list of examples](#importandexport-toc)

### Importing a site

```csharp

// Prepares the site import parameters
string websitePath = System.Web.HttpContext.Current.Server.MapPath("~/");
string sourceFilePath = "Packages\\APIExample_Site.zip";
string siteDisplayName = "Imported site";
string siteName = "ImportedSite";
string siteDomain = "127.0.0.1";

// Verifies that the system does not already contain a site with the given name
if (SiteInfoProvider.GetSiteInfo(siteName) == null)
{
    // Imports the site
    ImportProvider.ImportSite(siteName, siteDisplayName, siteDomain, sourceFilePath, websitePath, MembershipContext.AuthenticatedUser);
}

```

[> Back to list of examples](#importandexport-toc)

## Export

### Exporting an object (user)

```csharp

// Deletes temporary export files
try
{
    ExportProvider.DeleteTemporaryFiles();
}
catch
{
}

// Gets the user
UserInfo exportedUser = UserInfoProvider.GetUserInfo("Username");

// Ensures that the user exists
if (exportedUser != null)
{
    // Prepares the export parameters
    string websitePath = System.Web.HttpContext.Current.Server.MapPath("~/");
    string exportFileName = string.Format("APIExample_User_{0:yyyy-MM-dd_hh-mm}.zip", DateTime.Now);
    string exportFilePath = FileHelper.GetFullFilePhysicalPath(ImportExportHelper.GetSiteUtilsFolder(), websitePath) + "Export\\" + exportFileName;

    // Verifies that an export package with the given name doesn't already exist
    if (!File.Exists(exportFilePath))
    {
        // Exports the user object
        ExportProvider.ExportObject(exportedUser, exportFilePath, websitePath, MembershipContext.AuthenticatedUser);
    }
}

```

[> Back to list of examples](#importandexport-toc)

### Exporting a site

```csharp

// Deletes temporary export files
try
{
    ExportProvider.DeleteTemporaryFiles();
}
catch
{
}

// Prepares the export parameters
string websitePath = System.Web.HttpContext.Current.Server.MapPath("~/");
string exportFileName = string.Format("APIExample_Site_{0:yyyy-MM-dd_hh-mm}.zip", DateTime.Now);
string exportFilePath = FileHelper.GetFullFolderPhysicalPath(ImportExportHelper.GetSiteUtilsFolder(), websitePath) + "Export\\" + exportFileName;
string siteName = "ImportedSite";

// Verifies that the site exists
if (SiteInfoProvider.GetSiteInfo(siteName) != null)
{
    // Verifies that an export package with the given name doesn't already exist
    if (!File.Exists(exportFilePath))
    {
        // Exports the site
        ExportProvider.ExportSite(siteName, exportFilePath, websitePath, false, MembershipContext.AuthenticatedUser);
    }
}

```

[> Back to list of examples](#importandexport-toc)

### Deleting export packages from the file system

```csharp

// Prepares package parameters
string websitePath = System.Web.HttpContext.Current.Server.MapPath("~/");
string exportPath = FileHelper.GetFullFolderPhysicalPath(ImportExportHelper.GetSiteUtilsFolder(), websitePath) + "Export\\";
string filesToDelete = @"APIExample*.zip";

// Gets a list of export packages
string[] fileList = Directory.GetFiles(exportPath, filesToDelete);

// Deletes the files
foreach (string file in fileList)
{
    try
    {
        File.Delete(file);
    }
    catch
    {
        // Deletion was unsuccessful
    }
}

```

[> Back to list of examples](#importandexport-toc)
