Export / Import Files from umbraco CMS Media

3.3k Views Asked by At

As I need to export all my Media files from umbraco v 4.5.2 to umbraco v 6.0.5 ,

Is there any way or such package through which we can do the same.

1

There are 1 best solutions below

0
On

You can bulk import content using the CmsImport package (http://our.umbraco.org/projects/developer-tools/cmsimport). So if you created a file that referenced all your site images you could then import them under a content node on a new installation.

This is a bit of example razor code to run round your media images so you can list them out:

@using umbraco.cms.businesslogic.media;
@using uComponents.Core;
@using uComponents.Core.uQueryExtensions;
@using System
@{
  // Set default media root node id
  int rootNodeId = -1;

  // Get media node and iterate the children
  var m = new Media(rootNodeId);
  var imagesAndFolders = m.GetChildMedia();
  var sortedList = m.GetChildMedia().OrderBy(y => y.Text).OrderBy(x => x.ContentType.Alias);

        @{
          foreach (var c in sortedList)
          {
            var type = c.ContentType.Alias;
            switch (type)
            {
            case "Folder":
                //drill into folder
                break;
            default:
                var filePath = c.GetPropertyAsString("umbracoFile");
                var thumbPath = c.GetPropertyAsString("umbracoFile").Replace(".","_thumb.");
                var width = c.GetPropertyAsString("umbracoWidth");
                var height = c.GetPropertyAsString("umbracoHeight");

                  //allowing you to build a table of images

                  <a href="@filePath">@c.Text</a>
                  <a href="@filePath" class="imagePreview">preview &raquo;</a>
                  <a href="@filePath" itemprop="contentURL" download="@c.Text"><img itemprop="thumbnailUrl" src="@thumbPath" alt="@c.Text" /></a>
                break;
                }
            }
          }
}