Hi, I've been trying to figure out how to iterate through all the media nodes with the Api and get the names, parent id's, node id's and media type of each media node. But I apparently have to less knowledge about XmlNavigation. Can someone give me a hint? Thanx! (Can I use NodeFactory for media nodes?)
Finally, after tooo many hours I got it working, phew.
Whats working? It's a simple mirror function that replicates files from a folder on a remote host to the Umbraco media archive (with folder hierarchy). The user just selects a start node in Media and a physical path on the remote server.
The routine leaves existing files, it does not (yet) check for newer versions and does not delete files that has been deleted on the remote host. Also it's supposed to be scheduled... But for now it's working good enough so that I can go on with other things on the project. :)
Iterate media nodes with Api [solved]
Hi, I've been trying to figure out how to iterate through all the media nodes with the Api and get the names, parent id's, node id's and media type of each media node. But I apparently have to less knowledge about XmlNavigation. Can someone give me a hint? Thanx! (Can I use NodeFactory for media nodes?)
Hi,
I think GetMedia(int mediaId, bool deep) could do that. (Found in library class, and also available as xslt extension function)
Hope this helps.
Regards,
/Dirk
Yes, thanks, but that gives me an XPathNodeIterator, how to use that? :-k
nodes=umbraco.library.GetMedia(id, True);
While (nodes.MoveNext())
nodes.Current.Value
I'm stuck ](*,)
I've tried XPathNodeIterator.Current.GetAttribute(localName As String, namespaceURI As
String) with no luck
Yikes, this was hard. I struggled to get this working but kinda ugly solution:
[code] protected void Button1_Click(object sender, EventArgs e)
{
IterateMediaNodes(Convert.ToInt32(TextBox1.Text));
}
void IterateMediaNodes(int rootNodeId)
{
System.Xml.XPath.XPathNodeIterator it= umbraco.library.GetMedia(rootNodeId, true);
XmlNodesEnumerable xem = new XmlNodesEnumerable(it);
foreach (XmlNode node in xem)
{
try
{
Response.Write("NAME:" + node.Attributes.GetNamedItem("nodeName").Value + "
");
Response.Write("TYPE:" + node.Attributes.GetNamedItem("nodeTypeAlias").Value + "
");
Response.Write("PATH:" + node.Attributes.GetNamedItem("path").Value + "
");
Response.Write("umbracoFile:" + node.SelectSingleNode("./data[@alias='umbracoFile']").InnerText + "
");
Response.Write("umbracoExtension:" + node.SelectSingleNode("./data[@alias='umbracoExtension']").InnerText + "
");
}
catch (Exception)
{
}
if (node.HasChildNodes)
recurseNodes(node.ChildNodes);
}
}
protected void recurseNodes(XmlNodeList nodes)
{
foreach (XmlNode node in nodes)
{
try
{
Response.Write("NAME:" + node.Attributes.GetNamedItem("nodeName").Value + "
");
Response.Write("TYPE:" + node.Attributes.GetNamedItem("nodeTypeAlias").Value + "
");
Response.Write("PATH:" + node.Attributes.GetNamedItem("path").Value + "
");
Response.Write("umbracoFile:" + node.SelectSingleNode("./data[@alias='umbracoFile']").InnerText + "
");
Response.Write("umbracoExtension:" + node.SelectSingleNode("./data[@alias='umbracoExtension']").InnerText + "
");
}
catch (Exception)
{
}
if (node.HasChildNodes)
recurseNodes(node.ChildNodes);
}
}[/code]
I'm using the class XmlNodesEnumerable found here http://weblogs.asp.net/cazzu/archive/2004/03/09/86609.aspx
-o - the best solution is ofcourse getting the media node like this:
using umbraco.cms.businesslogic.media;
[code]Media m = new Media(nodeId);
foreach (Media mChild in m.Children)
...
if (mChild.ContentType.Alias=="Folder")
...
[/code]
Finally, after tooo many hours I got it working, phew.
Whats working? It's a simple mirror function that replicates files from a folder on a remote host to the Umbraco media archive (with folder hierarchy). The user just selects a start node in Media and a physical path on the remote server.
The routine leaves existing files, it does not (yet) check for newer versions and does not delete files that has been deleted on the remote host. Also it's supposed to be scheduled... But for now it's working good enough so that I can go on with other things on the project. :)
Ref http://articles.techrepublic.com.com/5100-10878_11-5805105.html (webservice file up/download).
is working on a reply...