Copied to clipboard

Flag this post as spam?

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


  • Rasmus Lynggaard 118 posts 325 karma points
    Oct 10, 2012 @ 18:10
    Rasmus Lynggaard
    0

    How do I get mediaitems stored as fullxml from codebehind

    I guess the subject says the most.

    I use DAMP and stores multiple media items in full xml.
    I can't figure out how to get the media items from the xml.
    If I use DAMP_Helper.GetImages(dampXml) I only get an array of urls and names. I really just want an array of media items - how do I do that?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 10, 2012 @ 18:20
    Jeroen Breuer
    1

    There are 2 things which you can do:

    1 use DynamicNode and DynamicXml in your codebehind. Have a look at this page. http://our.umbraco.org/forum/developers/razor/27417-Use-Razor-code-in-UserControl?p=1#comment102639 If you have your model in the codebehind you do the same things as in this example: http://damp.codeplex.com/SourceControl/changeset/view/cd320b3a2cd8#DAMP.Samples%2fDAMP-Razor.cshtml

    2 Look at the GetMediaTypeFiles(string dampXml, string mediaType) method in the DAMP_Helper.cs class and create it yourself with all the fields that you need.

    Jeroen

  • Rasmus Lynggaard 118 posts 325 karma points
    Oct 11, 2012 @ 14:38
    Rasmus Lynggaard
    0

    Thank you. I created a class which gave me the flexibility I was looking for.

    public class MediaItem
    {
    public string MediaItemXml { get; set; }
    public Media Media { get; set; }

    public static IEnumerable GetMediaItems(string dampXml)
    {
    var ret = new List();
    if (!string.IsNullOrEmpty(dampXml))
    {
    var doc = XDocument.Parse(dampXml);
    foreach (var node in doc.Descendants("mediaItem"))
    {
    var item = node.Descendants().First(x => x.Name == "Image" || x.Name == "File");
    if (item != null)
    {
    var mediaId = Int32.Parse(item.Attribute("id").Value);
    var media = new Media(mediaId);
    var mediaItem = MediaItem();
    mediaItem.MediaItemXml = node.ToString();
    mediaItem.Media = media;
    ret.Add(mediaItem);
    }
    }
    }
    return ret;
    }
    }
  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 11, 2012 @ 14:51
    Jeroen Breuer
    0

    In your example you're using the Media object. Each time you call a property this will do a call to the database. This can make your page a lot slower. It's better to get all the properties you need from the DAMP xml (the values are there already so it won't call the database) the same way you get the id.

    Jeroen

  • Rasmus Lynggaard 118 posts 325 karma points
    Oct 11, 2012 @ 15:04
    Rasmus Lynggaard
    0

    That's true - didn't think of that. Right now it doesn't really matter for my project, but might revisit this the next time I need it.

  • Jason 22 posts 41 karma points
    Nov 14, 2012 @ 23:06
    Jason
    0

    If I use DAMP for a property on a document type the data is stored in the umbraco.config xml, everything is fine.  The issue I'm having is I've created a custom media type and am using DAMP as a property along with other information.  The basic idea is to allow users to add meta data on images etc.  The issue I'm having is the XML for the DAMP for a custom media type doesn't get in the umbraco.config xml.  I'm only able to view the xml output from the media DAMP by looking at the

    var mediaData = new umbraco.cms.businesslogic.media.Media(Convert.ToInt32(item.id));
    string test = mediaData.GenericProperties[0].Value

    So I could parse the XML using the method in the DAMP_Helper.cs class, but I'm just looking to see if this is the best way to accomplish this.

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Nov 15, 2012 @ 09:29
    Jeroen Breuer
    0

    Here is some info about saving DAMP in the custom section: http://our.umbraco.org/projects/backoffice-extensions/digibiz-advanced-media-picker/digibiz-advanced-media-picker/23517-DAMP-10-in-custom-page. Don't forget this: "Remember that if you store your data as media xml the values don't get updated automatically if you change the media item in the media section. It's best to only store the id in the custom section unless you want to write a custom event which updates the media xml.".

    Like I said in this post you could extend the DAMP_Helper methods to get all the fields you need. That will give better performance because umbraco.cms.businesslogic.media.Media can be really slow.

    You could also try my new DAMP Razor Model.

    Than you could get all the info you need like this:

    //You can also get the DAMP Razor Model as a strongly typed model. 
    DAMP.RazorModel.Model items = new DAMP.RazorModel.Model(item.id.ToString());

    var media = items.First;
    <img src="@media.Url" alt="@media.Alt" /> 

    Jeroen

  • Craig100 1136 posts 2523 karma points c-trib
    Apr 07, 2013 @ 22:07
    Craig100
    0

    Is there a cheatsheet for the DAMP Razor Model somewhere? It would save literally hours of guesswork. I've now been trying all day to get images and crops out of DAMP both by ID and XML. What is the the most straightforward thing to do, have DAMP save as ID or XML when working with a non-MVC site (v6.0.3)?

    Craig

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Apr 16, 2013 @ 12:30
    Jeroen Breuer
    0

    On the project page you can see which properties can be used: http://our.umbraco.org/projects/backoffice-extensions/damp-property-editor-value-converter. It doesn't matter if you store it as xml or id. The converter works with both.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft