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?
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.
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; } }
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.
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.
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.
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)?
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?
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
Thank you. I created a class which gave me the flexibility I was looking for.
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
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.
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
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.
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:
Jeroen
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
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
is working on a reply...
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.