Copied to clipboard

Flag this post as spam?

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


  • James Borza 34 posts 95 karma points
    Mar 28, 2012 @ 02:57
    James Borza
    0

    How is the media file folder id generated? (creating media objects programmatically)

    Withing the media folder (site files) each media file has a bath like so:

    \media\12345\file_name.pdf

    What does the id in bold represent? It's not the media object ID (I've checked). I'm creating media objects and uploading the files to the media folder and was wondering how to create the folder name:

    Media media = Media.MakeNew(row["fName"].ToString(), MediaType.GetByAlias("File"), author, 3440);
    string folderPath = Server.MapPath("/media") + "\\" + media.getProperty("umbracoFile").Id;
    string fullPath = folderPath + "\\" + fileName;
    
    Directory.CreateDirectory(folderPath);
    File.WriteAllBytes(fullPath, bytes);
    
    media.getProperty("umbracoFile").Value = "/media/" + media.getProperty("umbracoFile").Id + "/" + row["fName"].ToString();
    media.getProperty("umbracoExtension").Value = "pdf";
    FileInfo fileInfo = new FileInfo(fullPath);
    media.getProperty("umbracoBytes").Value = fileInfo.Length;
    
    //link media object to document
    doc.getProperty("file").Value = media.getProperty("umbracoFile").Id;
  • James Borza 34 posts 95 karma points
    Mar 28, 2012 @ 03:08
    James Borza
    0

    Nevermind I found out it's generated from the property id like I thought. The code above is right!

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 28, 2012 @ 03:15
    Lee Kelleher
    0

    Hi James,

    The id in the filepath maps to the row id for the "umbracoFile" property in the cmsPropertyData database table.

    Not sure how to access that via the API... to be honest, I'd have thought that media.getProperty("umbracoFile").Id would have worked?

    Cheers, Lee.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 28, 2012 @ 03:16
    Lee Kelleher
    0

    Doh! Cross-posted, didn't see your reply before writing mine! :-)

  • James Borza 34 posts 95 karma points
    Mar 28, 2012 @ 03:18
    James Borza
    0

    Thanks for the reply anyways Lee!

Please Sign in or register to post replies

Write your reply to:

Draft