Copied to clipboard

Flag this post as spam?

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


  • Pete 213 posts 285 karma points
    Sep 17, 2012 @ 14:25
    Pete
    0

    Set a property's value on a media folder thru api

    How would you got about setting a value to a property on a existing media folder?

    I've got the following but does'nt seem to work.

    var startMedia = uQuery.GetMediaByName(foldername).FirstOrDefault();
    var mediaFolder = startMedia.Id;
    var d = new umbraco.cms.businesslogic.web.Document(1362);
    d.getProperty("galleryPassword").Value = password.ToString();
    d.Publish(new umbraco.BusinessLogic.User(0));
    umbraco.library.UpdateDocumentCache(d.Id);
  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Sep 17, 2012 @ 17:27
    Jeroen Breuer
    0

    On this page you can see how I set properties on a media item: http://damp.codeplex.com/SourceControl/changeset/view/62425cfc1854#DAMP.Samples%2fInstaller.ascx.cs. See the CreateMedia method. You shouldn't use the Document object, but the Media object.

    Jeroen

  • Pete 213 posts 285 karma points
    Sep 17, 2012 @ 17:35
    Pete
    0

    Thanks jeroen.

    So it's using

    Media media = Media.MakeNew(name, mediaType, adminUser, parentId);
    and then
    media.getProperty("umbracoFile").Value = umbracoFile;

    To set the property, but how to you reference an existing media item? if it was a document you would just use Document doc = Document(nodeid); but that does'nt seem to work for an existing media item?

    Pete

  • Mat 8 posts 28 karma points
    Sep 20, 2012 @ 06:58
    Mat
    0

    Try something like this

    var reqMedia = new umbraco.cms.businesslogic.media.Media(Id);
    if (reqMedia != null)
    {
        //do something
    }
  • Mat 8 posts 28 karma points
    Sep 20, 2012 @ 07:06
    Mat
    0

    Alternatively, I think this too should work

    Media m = new Media(id);
    string valueFromMedia = m.getProperty("propertyname").Value
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies