Copied to clipboard

Flag this post as spam?

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


  • Steven 12 posts 83 karma points
    May 30, 2013 @ 10:45
    Steven
    0

    Umbraco API Media(Service) v6, the way to get the MediaFolder of a new item

    I'm using the v6 API to import content and files into a new Umbraco website. What I would like to do is retrieve all file information from the old site and insert it in the Umbraco Media tree.
    What is the (best) way to retrieve the (future) ID of the Media directory where the file will be stored? (So I can move the existing file to the correct Media directory).

    To give an impression in code;

    Umbraco.Core.Services.MediaService ms = new Umbraco.Core.Services.MediaService(new Umbraco.Core.Persistence.RepositoryFactory());
    Media newItem = (Media)ms.CreateMedia(mediaName, intParentId, newMediaType, 0);
    newItem.Properties["umbracoWidth"].Value = intImageWidth;
    newItem.Properties["umbracoHeight"].Value = intImageHeight;
    newItem.Properties["umbracoBytes"].Value = itemByteSize;
    newItem.Properties["umbracoExtension"].Value = ext;

    // So what ID will/should be used as directory in the umbracoFile path?
    // [/media/???????????/photo.jpg]
    newItem.Properties["umbracoFile"].Value = strFutureMediaFolderUrl;

    ms.Save(newItem);
    System.IO.File.Copy(strSourceFilePath, HttpContext.Current.Server.MapPath(strFutureMediaFolderUrl));

    I've looked for a property on the Media object, as well on the MediaService, but can't find it...

Please Sign in or register to post replies

Write your reply to:

Draft