I am trying to load an xml file from the media library but am having an issue with the pathing. I have been able to load the xml when the xml file is located in the actual server files, or when it is on another hosted site, but not when the file is in the media library. Does the xml file have to be a physical file hosted somewhere?
Here is my code for retrieving the path of 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 load the xml I am doing the following:
XmlDocument xDoc = new XmlDocument();
xDoc.Load(Server.MapPath(url));
The path it returns is correct, as I have tested putting it in an anchor tag to see if it would link to the xml file, and it does. I have found similar posts on this site but none seem to address media library items in the context of xml.Load.
Any information on if this is possible or what I can do to make it work would be much appreciated.
Thank you.