Copied to clipboard

Flag this post as spam?

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


  • Darryl Godden 145 posts 197 karma points
    Mar 19, 2010 @ 13:10
    Darryl Godden
    0

    Update media

    Hi all,

    Hopefully you can point me in the right direction with the time-pressing problem, we have a media content type, which is a meeting and has meeting date, meeting location properties etc...

    After a user has created a meeting I need to create a form to allow them to go back in and upload an agenda and minutes at a later date, the agenda and minutes upload type exist in the media content.

    To create a new media of type meeting I use:

    MediaType mt = MediaType.GetByAlias("Meeting");
            User author = User.GetUser(0);
    
            Media EV = Media.MakeNew(ddlSelectMeeting.SelectedValue.ToString(), mt, author, 1346);

    What do I use to update an existing media content type? The meeting title and meeting ID are in a drop down list which the user selects from:

    Media m = new Media(1346);
            foreach (Media mChild in m.Children)
            {
                String meetingTitle = mChild.getProperty("meetingTitle").Value.ToString();
                String nodeID = mChild.Id.ToString();
    
                ddlSelectMeeting.Items.Add(new ListItem(meetingTitle, nodeID));
            }

    Thanks,

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 19, 2010 @ 15:15
    Dirk De Grave
    0

    Media can be updated as any other "content" node, just use getProperty("alias") to get the reference to the property of the media type and use .Value to get or set the value depending on selected values.

     

    Does that make sense?

     

    Cheers,

    /Dirk

  • Darryl Godden 145 posts 197 karma points
    Mar 22, 2010 @ 14:09
    Darryl Godden
    0

    Hi Dirk,

    Apologies, I had to go off early, it was solved like this:

    MediaType mt = MediaType.GetByAlias("Meeting");
            User author = User.GetUser(0);
    
            //Media EV = Media.MakeNew(ddlSelectMeeting.SelectedValue.ToString(), mt, author, 1346);
            Media EV = new Media(Convert.ToInt32(ddlSelectMeeting.SelectedValue.ToString()));
    
            if (EV == null)
            {
                return;
            }
    
            if (fuAgenda.HasFile)
            {
                // Upload the file to the server, once we have our unique media ID.
                System.IO.Directory.CreateDirectory(Request.PhysicalApplicationPath + "/media/" + EV.Id);
                fuAgenda.SaveAs(Request.PhysicalApplicationPath + "/media/" + EV.Id + "/" + fuAgenda.FileName);
    
                // Update the file property.
                umbraco.cms.businesslogic.property.Property propfile = EV.getProperty("meetingAgenda");
                propfile.Value = "/media/" + EV.Id + "/" + fuAgenda.FileName;
    
                EV.Save();
            }

     

    The important bit is the new Media, then the reference to the content node you are updating.

    Thanks.

  • Rob Watkins 369 posts 701 karma points
    Mar 03, 2011 @ 13:42
    Rob Watkins
    0

    I don't really understand your SaveAs line - why are you saving into a folder named with the ID of the original media item?

    My media folder is sectioned into numeric subfolders, but those folders don't bear any relation to the ids used for media files, or media folders, or anything really.

    So where do they come from? Are they important, or can I just make them up and set the umbracoFile to the resulting filename?

    I don't see how I can use the media ID as the folder number because there may be clashes due to the fact the folder numbers appear to generated using a completely different system.

  • Rob Watkins 369 posts 701 karma points
    Mar 03, 2011 @ 13:58
    Rob Watkins
    0

    Never, mind, found a thread that covers exactly what I want to do, no idea why it was no returned on my original Google!

    http://our.umbraco.org/forum/developers/api-questions/16310-Create-new-media-using-API

Please Sign in or register to post replies

Write your reply to:

Draft