Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • g3t 23 posts 114 karma points
    Sep 21, 2017 @ 11:44
    g3t
    0

    Is there a tool or some technique to extract all file from a media folder that works in 7.4 . Tried Export media package but no luck in version 7 and above. thanks

  • Alex Skrypnyk 4637 posts 16595 karma points MVP 2x admin
    Sep 21, 2017 @ 11:47
    Alex Skrypnyk
    0

    Hi g3t

    Where do you want to export media files? Why?

    Thanks,

    Alex

  • g3t 23 posts 114 karma points
    Sep 21, 2017 @ 13:37
    g3t
    1

    Hi Alex

    Would be great to be able to collect and export a folder as zip like the Export Media package.

    But any way that would allow downloading the whole folder instead of having to click the media link in the properties tab for each media item to download it.

    Its really for extra archiving purposes. I'm not able to upgrade from SQL CE for a while yet.

    thanks

  • Ben 5 posts 117 karma points
    Jun 07, 2018 @ 11:11
    Ben
    0

    Hey,

    here is how i do it most of the time;

    add this code to a cshtml file of yours, the 9126 is the id of the parent media item (usually a folder)

    @{
        var folder = Umbraco.TypedMedia(9126);
        var mediaItems = folder.Descendants();
    }
    
    @if (mediaItems.Any())
    {
    <ul>
    
        @foreach (var media in mediaItems)
        {
            <li>
                <a href="@media.Url">@media.Name</a>
            </li>
        }
    </ul>
    }
    

    now navigate to that page, where you added the snipped

    use a chrome extension, called "fatkun image downloader". That tool will render all image links to a new page, and then you can simple use the save image button, you can even filter on extension

    sample screen of the chrome extesion

  • Andy Neil 4 posts 76 karma points
    Jun 07, 2018 @ 13:15
    Andy Neil
    0

    Hi There,

    Here's some code that will give you all the media listed as a CSV, but you could modify it to get the file contents and do something with the file streams.

    var sb = new StringBuilder();
    
            var uh = new UmbracoHelper(UmbracoContext.Current);
            var homeNodes = uh.UmbracoContext.MediaCache.GetAtRoot();
    
            foreach (var homeNode in homeNodes)
            {
                sb.AppendLine(string.Format("{0},{1},TOP LEVEL FOLDER,n/a,{2}", homeNode.Id, homeNode.Name,
                    homeNode.GetPropertyValue<bool>("keep", false)));
                var mediaDescendants = homeNode.Descendants(20);
                foreach (var descendant in homeNode.Descendants())
                {
                    sb.AppendLine(string.Format("{0},{1},{2},{3},{4}", descendant.Id, homeNode.Name, descendant.AncestorOrSelf(1).Name,
                        descendant.DocumentTypeAlias.InvariantContains("folder") ? descendant.Name + "[Folder]" : descendant.Url, 
                        descendant.GetPropertyValue<bool>("keep", true, false)));
                }
            }
    
            var rootPath = HttpContext.Server.MapPath("~");
            var filePath = "media/AllMedia.csv";
            var fullPath = Path.Combine(rootPath, filePath);
    
            System.IO.File.WriteAllText(fullPath, sb.ToString());
    

    Hope that's of some use. Cheers, Andy

  • M N 102 posts 179 karma points
    1 week ago
    M N
    0

    Searched around for something similar g3t .. Ended up having to write something,

    Below is a recursive function that should do what you want. It will make an exact copy of your Media Library structure, but in windows folder. Files are physically copied from the /media folder.

    private void ExportAllMedia(string basePath, string curFolder,  IMedia uNode)
    {
        var _contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
        var _mediaService = ApplicationContext.Current.Services.MediaService;
        var folderType = _contentTypeService.GetMediaType("Folder");
    
        Directory.CreateDirectory(curFolder);
    
        IEnumerable<IMedia> curMedia = null;
    
        if (uNode == null)
            curMedia = _mediaService.GetRootMedia();
        else
            curMedia = uNode.Children();
    
    
        // loop through folders
        foreach (IMedia media in curMedia.Where(a=>a.ContentTypeId == folderType.Id))
        {
            // recurse inward with this folder
            ExportAllMedia(basePath, curFolder + "\\"  + media.Name , media);
        }
    
        // regular files
        foreach (IMedia media in curMedia.Where(a => a.ContentTypeId != folderType.Id))
        {
            string filePath = media.GetValue<string>("umbracoFile").Replace("/", "\\");
            string source = basePath + filePath;
            string destination = Path.Combine(curFolder, Path.GetFileName(source));
    
            System.IO.File.Copy(source, destination);
        }
    }
    

    Usage

    string basepath = HttpContext.Current.Server.MapPath("~/").TrimEnd('\\');
    string savePath = HttpContext.Current.Server.MapPath("~/App_Data/ExportMedia/" + DateTime.Now.Ticks);
    ExportAllMedia(basepath, savePath, null);
    

    It won't zip it, but hey you can probably sort that out :)

    Cheers

Please Sign in or register to post replies

Write your reply to:

Draft