Take the community feedback survey now.
AI OnAI Off
Take the community feedback survey now.
Hi,
This is the code we're using to export assets:
<%@ Page Language="C#" AutoEventWireup="true" Inherits="System.Web.UI.Page" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="EPiServer" %>
<%@ Import Namespace="EPiServer.Core" %>
<%@ Import Namespace="EPiServer.Core.Transfer" %>
<%@ Import Namespace="EPiServer.DataAbstraction" %>
<%@ Import Namespace="EPiServer.DataAccess" %>
<%@ Import Namespace="EPiServer.Enterprise" %>
<%@ Import Namespace="EPiServer.Implementation" %>
<%@ Import Namespace="EPiServer.ServiceLocation" %>
<%@ Import Namespace="EPiServer.Personalization.VisitorGroups" %>
<%@ Import Namespace="EPiServer.Framework.Cache" %>
<%@ Import Namespace="EPiServer.Framework.Blobs" %>
<script runat="server">
private Injected<ITabDefinitionRepository> _tabDefinitionRepository;
private Injected<IPropertyDefinitionRepository> _propertyDefinitionRepository;
private Injected<ContentListDB> _contentListDB;
private static IContentRepository _contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
private static DecoratedClassFactory CreateClassFactory(string type, string id)
{
Type concreteType = Type.GetType(type, true);
return Activator.CreateInstance(concreteType, new Object[] { id }) as DecoratedClassFactory;
}
private static void WriteError(System.Web.HttpResponse response, string errorMessage)
{
response.Clear();
response.Write("<span style=\"color: red;\">Error: " + errorMessage + "</span><br />");
response.End();
}
private void Page_Load(object sender, System.EventArgs e)
{
DataExporter exporter = new DataExporter();
//Get all page references and data
List<PageReference> startPageReferenceList = new List<PageReference>();
List<ContentData> startPageDataList = new List<ContentData>();
ContentFolder rootFolder = _contentRepository.GetChildren<ContentFolder>(EPiServer.Web.SiteDefinition.Current.GlobalAssetsRoot).FirstOrDefault() as ContentFolder;
exporter.Frames.AddRange(Frame.List());
exporter.TabDefinitions.AddRange(_tabDefinitionRepository.Service.List());
foreach (var propertyDefinition in _propertyDefinitionRepository.Service.ListDynamic())
{
exporter.DynamicPropertyDefinitions.Add(propertyDefinition);
}
exporter.Categories.AddRange(Category.GetRoot().Categories);
//Set rootFolder to exporter
ExportSource sourceRoot = new ExportSource(rootFolder.ContentLink, EPiServer.Core.Transfer.ExportSource.RecursiveLevelInfinity);
exporter.SourceRoots.Add(sourceRoot);
//property settings
exporter.ExportPropertySettings = true;
exporter.IncludeImplicitContentDependencies = true;
if (Request.QueryString["debug"] != null)
{
Response.Clear();
exporter.Stream = new MemoryStream();
exporter.Export();
if (exporter.Log.Errors.Count > 0)
{
foreach (string s in exporter.Log.Errors)
{
Response.Write(s + "<br>");
}
}
else
{
Response.Write("OK");
}
}
else
{
Response.Clear();
string file = Path.GetTempFileName();
exporter.Stream = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Write | FileAccess.Read, FileShare.Read);
exporter.Export();
exporter.Close();
if (exporter.Log.Errors.Count > 0)
{
throw new Exception("errors occured,try &debug=true");
}
Response.ContentType = "binary/octet-stream";
Response.AddHeader("Content-disposition", "attachment; filename=CatalogAssets.episerverdata");
exporter.Stream.Close();
Response.WriteFile(file);
}
Response.End();
}
</script>
You might need to change it a bit, such as the root folder.
Regards,
/Q
Hello!
Is there any way to export all assets in a media folder?
The current migration tool only lets me export assets references by pages, or stand-alone assets if I select them one by one, which takes forever since there are like 500 assets.
Thanks!