you could use umbraco.library.GetMedia(mediaId, true) to fetch all images from a specific 'Projects' folder. From xslt, you'd use umbraco.library:GetMedia() (mind the semicolon instead of just a dot) whereas in c# code, you just use umbraco.library.GetMedia().
First paramter is the id of the 'Projects' folder, second parameter (true) tells function to retrieve all images below the 'Projects' folder (may be including the 'Projects' folder media item as well...)
Dirk is right, but the problem is that this won't work for the root folder (with id -1). You can't use that in umbraco.library.GetMedia. Here is a solution which I used in C# (which probably will also work in Razor).
public System.Xml.Linq.XDocument GetMediaXML(int mediaId)
{
//Create an empty xmlDocument.
System.Xml.Linq.XDocument xmlDocument = new System.Xml.Linq.XDocument(
new System.Xml.Linq.XElement("Media")
);
if (mediaId == -1)
{
//If the mediaId is -1 loop through all the top media nodes.
using (umbraco.DataLayer.IRecordsReader dr = SqlHelper.ExecuteReader("Select id from umbracoNode where nodeObjectType = @type And parentId = -1 order by sortOrder",
SqlHelper.CreateParameter("@type", umbraco.cms.businesslogic.media.Media._objectType)))
{
while (dr.Read())
{
//Get the hierarchical xml from each topnode and add it to the xmlDocument.
xmlDocument.Root.Add(System.Xml.Linq.XElement.Parse(umbraco.library.GetMedia(dr.GetInt("id"), true).Current.OuterXml));
}
}
}
else
{
//Get the hierarchical xml from the media id and add it to the xmlDocument.
xmlDocument.Root.Add(System.Xml.Linq.XElement.Parse(umbraco.library.GetMedia(mediaId, true).Current.OuterXml));
}
return xmlDocument;
}
Get All Images in Media Gallery?
I have such structure in media
Media(folder)
--Sites(folder)
----Projects(folder)
---------ImageOfProject(image)
----Projects(folder)
---------ImageOfProject(image)
How can I get all images of all projects?
HI Anton,
you could use umbraco.library.GetMedia(mediaId, true) to fetch all images from a specific 'Projects' folder. From xslt, you'd use umbraco.library:GetMedia() (mind the semicolon instead of just a dot) whereas in c# code, you just use umbraco.library.GetMedia().
First paramter is the id of the 'Projects' folder, second parameter (true) tells function to retrieve all images below the 'Projects' folder (may be including the 'Projects' folder media item as well...)
Cheers,
/Dirk
Dirk is right, but the problem is that this won't work for the root folder (with id -1). You can't use that in umbraco.library.GetMedia. Here is a solution which I used in C# (which probably will also work in Razor).
Jeroen
c# image library may help you with that, and the codes here is playing well. thank you for helping.
is working on a reply...