Try our conversational search powered by Generative AI!

How to bulk import files in EPiServer CMS

Vote:
 

How to bulk import files in EPiServer CMS from batch file or something similar to that.?

#150153
Jun 13, 2016 9:02
Vote:
 
#150155
Jun 13, 2016 9:38
Vote:
 

thanks  Dejan Caric any API that can automate the process of upload?

#150157
Jun 13, 2016 9:57
Vote:
 

I posted a link to the API you can.

Where do you want to upload the files?

Are they zipped? Do you have to upload them to EPi first, or is it ok to place them in a shared folder and execute the import script?

A long time ago, I wrote a blog post on how I imported content from some legacy system into EPi: http://www.dcaric.com/blog/importing-archived-articles-from-legacy-system-into-episerver-cms

I received exported content in the XML format. XML files were zipped:

<?xml version="1.0" encoding="ISO-8859-1"?>
<io>
  <article id="XXX" lastmodified="2010-06-12 11:57:22.0" publishdate="2010-06-12 11:57:22.0">
    <field name="TITLE">Article 1</field>
	<field name="PREAMBLE">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</field>
	<field name="MAINBODY">
		<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
		<p>Pellentesque blandit tincidunt porta.</p>
		<p>Etiam a leo in eros consequat bibendum ut a nibh.</p>
		<p>Aliquam augue orci, vestibulum at sollicitudin at, malesuada non neque.</p>
	</field>
	<field name="ARTICLEIMAGE">http://dummyimage.com/600x400/3978f7/000000.png</field>
  </article>
</io>

I wrote a tool in admin mode that extracts the ZIP file, fetches the image from the internet, and creates a new page in the Archive folder.

Hope it helps.

#150158
Jun 13, 2016 10:10
Vote:
 

i need to upload directly to "Test" folder under "for alll sites".

#150167
Jun 13, 2016 11:36
Vote:
 

This was written on top of the Alloy site so you may need to change some stuff

var contentAssetHelper = ServiceLocator.Current.GetInstance<ContentAssetHelper>();
                // get an existing content asset folder or create a new one
                var assetsFolder = contentAssetHelper.GetOrCreateAssetFolder(new ContentReference(assetfolderid));
                var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
                var blobFactory = ServiceLocator.Current.GetInstance<EPiServer.Framework.Blobs.BlobFactory>();
                string name = "";
                string ext = "";
 file = contentRepository.GetDefault<ImageFile>(assetsFolder.ContentLink);
                    name = url.Substring(url.LastIndexOf('/') + 1);
                    ext = name.Substring(name.IndexOf('.'));
                    name = url.Replace(ext, "").Trim();
file.Name = name;
                var blob = blobFactory.CreateBlob(file.BinaryDataContainer, "." + ext);
                var data = GetData(url);
                blob.Write(new System.IO.MemoryStream(data));
                file.BinaryData = blob;
                var fileRef = contentRepository.Save(file, EPiServer.DataAccess.SaveAction.Publish);
private byte[] GetData(string url)
        {
            try
            {
                if (url.StartsWith("/"))
                {
                    url = "https://portal.ektron.com" + url;
                }
                using (var client = new System.Net.WebClient())
                {
                    byte[] data = client.DownloadData(new Uri(url));
                    return data;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }
#150200
Jun 13, 2016 19:27
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.