Programatically create mirror of content tree within media.
Hi all,
I am a umbraco newbie been playing with it for 2 weeks now. What an amazing templating engine. Since integrating DAMP I have a requirement where I want to store pageicons for each page, also I would like to store my media under a heirachy mirroring my content tree. I am familiar with event handlers and have found the following code which has got me started however I am stumped where to go from here.
using System; using System.Collections.Generic;
using System.Web;
using umbraco.BusinessLogic; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.media; using umbraco.cms.businesslogic.web; using umbraco.cms.businesslogic.property;
using System.Web.Security; using System.Linq;
public class CreateClientMediaFolder : umbraco.BusinessLogic.ApplicationBase {
public CreateClientMediaFolder() { Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish);
MediaType folderType = MediaType.GetByAlias("folder"); //initialise collection of type media where the first or default item is equal to 'ContentImages'. Media Media1 = Media.GetMediaOfMediaType(folderType.Id).FirstOrDefault(m => m.Text == "ContentImages" && m.ChildCount >= 0);
//if I have the parent folder details if (Media1 != null) { //initialise new media item Media newFolder; //if parent folder doesn't contain NewContentName if(Media1.Children.FirstOrDefault(c => c.Text == NewContentName) == null)
//create new folder mirroring the newly saved page. newFolder = Media.MakeNew(NewContentName, folderType, User.GetUser(0), Media1.Id); }
}
}
Currently I have a tested solution where on newDocument or Document_Afterpublish event a new folder is created under contentImages parent node if not already existing. I want to extend this to allow a complete mirror of the content tree gracefully.
Have anyone ever tried this before. Some direction would be appreciated.
update: I need to find out nodename of the parent document. Then I can passthis to, where ParentName is same as parent node. This should then create the folder in the corresponding media node.
Programatically create mirror of content tree within media.
Hi all,
I am a umbraco newbie been playing with it for 2 weeks now. What an amazing templating engine. Since integrating DAMP I have a requirement where I want to store pageicons for each page, also I would like to store my media under a heirachy mirroring my content tree. I am familiar with event handlers and have found the following code which has got me started however I am stumped where to go from here.
using System;
using System.Collections.Generic;
using System.Web;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using umbraco.cms.businesslogic.media;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.property;
using System.Web.Security;
using System.Linq;
public class CreateClientMediaFolder : umbraco.BusinessLogic.ApplicationBase
{
public CreateClientMediaFolder()
{
Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish);
}
void Document_AfterPublish(Document sender, PublishEventArgs e)
{
string NewContentName = sender.Text;
MediaType folderType = MediaType.GetByAlias("folder");
//initialise collection of type media where the first or default item is equal to 'ContentImages'.
Media Media1 = Media.GetMediaOfMediaType(folderType.Id).FirstOrDefault(m => m.Text == "ContentImages" && m.ChildCount >= 0);
//if I have the parent folder details
if (Media1 != null)
{
//initialise new media item
Media newFolder;
//if parent folder doesn't contain NewContentName
if(Media1.Children.FirstOrDefault(c => c.Text == NewContentName) == null)
//create new folder mirroring the newly saved page.
newFolder = Media.MakeNew(NewContentName, folderType, User.GetUser(0), Media1.Id);
}
}
}
Currently I have a tested solution where on newDocument or Document_Afterpublish event a new folder is created under contentImages parent node if not already existing. I want to extend this to allow a complete mirror of the content tree gracefully.
Have anyone ever tried this before. Some direction would be appreciated.
Thanks
update: I need to find out nodename of the parent document. Then I can passthis to, where ParentName is same as parent node. This should then create the folder in the corresponding media node.
Media Media1 = Media.GetMediaOfMediaType(folderType.Id).FirstOrDefault(m => m.Text == "ParentName" && m.ChildCount >= 0);
is working on a reply...