I am trying to download an xml file from a media library, but I have a problem with the outline. I was able to download xml when the XML file is in the actual server files, or when it is on another hosted site, but not when the file is in the library. Should the xml file be a physical file hosted somewhere?
Here is my code to get the path to the media item:
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.Item sampleItem = master.GetItem("/sitecore/media library/Files/eBooks/testxml");
Sitecore.Data.Items.Item sampleMedia = new Sitecore.Data.Items.MediaItem(sampleItem);
string url = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(sampleMedia));
Then, when I download xml, I do the following:
XmlDocument xDoc = new XmlDocument();
xDoc.Load(Server.MapPath(url));
The return path is correct, as I tested it in the anchor tag to see if it would reference the xml file, and it does. I found similar posts on this site, but none of them relate to media library items in the context of xml.Load.
Any information on whether this is possible or what I can do to make it work would be greatly appreciated.
Thank.
source
share