Copied to clipboard

Flag this post as spam?

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


  • Alex Perotti 53 posts 94 karma points
    Jun 25, 2013 @ 20:21
    Alex Perotti
    0

    Creating media programmaticaly, properties update

    Hi all,

     

    problably I'm missing something... I'm trying to create some medias (images) but properties (size, height, and so on) don't update. Only the file is correct.

    Here's the code.

    Thanks in advance

    var mediaName = sender.getProperty("name").Value + " " + String.Format("{0:d-M-yyyy HHmmss}", DateTime.Now);
    
                    var media = Media.MakeNew(mediaName, MediaType.GetByAlias("image"), umbraco.BasePages.UmbracoEnsuredPage.CurrentUser, 
                        Convert.ToInt32(ConfigurationManager.AppSettings.Get("GrabzItMediaFolder")));
    
                    string storagePath = ConfigurationManager.AppSettings.Get("MediaRootPath") + media.Id.ToString();
    
                    System.IO.Directory.CreateDirectory(storagePath);
    
                    string fullFilePath = storagePath + "\\" + mediaName + ".jpeg";
    
                    media.getProperty("umbracoExtension").Value = "jpeg";
    
    
                    Bitmap img = (Bitmap)Image.FromFile(temporaryPath, true);
    
                    img.Save(fullFilePath, ImageFormat.Jpeg);
    
    
                    media.getProperty("umbracoHeight").Value = img.Height.ToString();
                    media.getProperty("umbracoWidth").Value = img.Width.ToString();
    
                    media.getProperty("umbracoBytes").Value = new FileInfo(fullFilePath).Length;
                    media.getProperty("umbracoFile").Value = fullFilePath;
                    media.XmlGenerate(new XmlDocument());
    
                    media.Save();
    
                    sender.getProperty("screenshot").Value = media.Id;
    
    
                    img.Dispose();
                    File.Delete(temporaryPath);

  • Josiah D Thoen 18 posts 63 karma points
    Jun 25, 2013 @ 21:24
    Josiah D Thoen
    0

    I just found this help doc: http://our.umbraco.org/Documentation/Reference/Management-v6/Models/Media

    I would try the new MediaService and then do .SetValue(string propertyTypeAlias, object value)

     

  • Alex Perotti 53 posts 94 karma points
    Jun 25, 2013 @ 21:26
    Alex Perotti
    0

    Unfortunatly I'm working on umbraco 4.11 and that's for 6.x

    Thank you anyway :)

  • Josiah D Thoen 18 posts 63 karma points
    Jun 25, 2013 @ 23:18
    Josiah D Thoen
    0

    You may have already reviewed this post but if not it may help: http://our.umbraco.org/forum/developers/api-questions/3477-Creating-Media-Programatically?p=1

  • Alex Perotti 53 posts 94 karma points
    Jun 26, 2013 @ 20:50
    Alex Perotti
    0

    Thanks for your reply, I'm working on this project in my spare time, I will check that solution asap :)

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Sep 09, 2013 @ 15:21
    Andy Butland
    0

    Just wondering if you solved this Alex, as I'm having the same issue - umbracoFile is the only one that looks to work for me.

  • Alex Perotti 53 posts 94 karma points
    Sep 09, 2013 @ 15:25
    Alex Perotti
    0

    Unfortunatly no.

    This one is a personal hobby project and I'm not currently working on it. I will publish some news if I will manage to solve this issue

Please Sign in or register to post replies

Write your reply to:

Draft