Copied to clipboard

Flag this post as spam?

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


  • Shaun 248 posts 475 karma points
    Nov 30, 2009 @ 16:48
    Shaun
    1

    accessing umbraco.library.GetMedia in a user control

    Hi

    Does anyone have any pointers for accessing GetMedia information in a .Net control? I'm trying to read the value of a media Item in, but I can't seem to work out the correct method.

    At the moment all of these are returning the same string -/media/372/test.docdoc9216

     System.Xml.XPath.XPathNodeIterator xn = umbraco.library.GetMedia(Convert.ToInt32(_DownloadID),false);
                System.Xml.XPath.XPathNodeIterator xName = xn.Current.Select("@nodeName");
                System.Xml.XPath.XPathNodeIterator xSize = xn.Current.Select("data[@alias = 'umbracoBytes']");
                System.Xml.XPath.XPathNodeIterator xFilePath = xn.Current.Select("data[@alias = 'umbracoFile']");


                lblName.Text = xName.Current.Value;
                lblSize.Text = xSize.Current.Value;
                string strFilePath = xFilePath.Current.Value;

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Nov 30, 2009 @ 16:54
    Jeroen Breuer
    1

    You can just use the Media-object.

    Media mediaItem = new Media(id)
  • Shaun 248 posts 475 karma points
    Nov 30, 2009 @ 17:22
    Shaun
    0

    Brilliant, thats done the trick. Thanks Jeroen.

  • David Conlisk 432 posts 1008 karma points
    Jul 07, 2011 @ 17:11
    David Conlisk
    0

    Thanks Jeroen - saved me some time there!

    One thing to note, if you don't already have access to the Media object, you may need to add references to the umbraco dlls cms.dll and businesslogic.dll in your project. Then add the following line at the top of your user control:

    using umbraco.cms.businesslogic.media;

    Cheers,

    David

Please Sign in or register to post replies

Write your reply to:

Draft