User control not working Options
ChristophS
Posted: Thursday, February 21, 2008 2:13:19 PM
Rank: Devotee

Joined: 2/4/2008
Posts: 38
ChristophS
Posted: Thursday, February 21, 2008 2:19:01 PM
Rank: Devotee

Joined: 2/4/2008
Posts: 38
Hi there,

I found this control earlier on the forum here to put blog posts automatically into folders ordered by date, so like this: 2008\02\21\Blogpost. Now I need this thing for another section on my site too. I have a news section and I need the news articles also to be automatically put into these date folders.

I'm using the following code:
Code:

using System;
using System.Collections.Generic;
using System.Text;
using umbraco.cms.businesslogic.web;
using umbraco;

namespace AutoDateFolder
{
    class AutoDateFolder
    {
        public bool Execute(umbraco.cms.businesslogic.web.Document documentObject, umbraco.interfaces.IAction action)
        {
            if (documentObject.ContentType.Alias == "umbracoBlogPost")
            {

                if (new Document(documentObject.Parent.Id).ContentType.Alias != "umbracoBlogDateFolder")
                {
                    string[] refNr =
                        (documentObject.CreateDateTime.Year.ToString() + "-" +
                        documentObject.CreateDateTime.Month.ToString() + "-" +
                        documentObject.CreateDateTime.Day.ToString())
                        .Split("-".ToCharArray());
                    if (refNr.Length == 3)
                    {
                        // Check if year exists   
                        Document year = null;
                        foreach (umbraco.BusinessLogic.console.IconI i in documentObject.Parent.Children)
                        {
                            if (i.Text == refNr[0])
                            {
                                year = new Document(i.Id);
                                break;
                            }
                        }

                        if (year == null)
                        {
                            year = Document.MakeNew(refNr[0], DocumentType.GetByAlias("umbracoBlogDateFolder"), documentObject.User, documentObject.Parent.Id);
                            year.Publish(documentObject.User);
                            umbraco.library.PublishSingleNode(year.Id);
                        }
                        else
                            umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, documentObject.User, documentObject.Id, "executed - year not null");


                        // Check if month exists   
                        Document month = null;
                        foreach (umbraco.BusinessLogic.console.IconI i in year.Children)
                        {
                            if (i.Text == refNr[1])
                            {
                                month = new Document(i.Id);
                                break;
                            }
                        }
                        if (month == null)
                        {
                            month = Document.MakeNew(refNr[1], DocumentType.GetByAlias("umbracoBlogDateFolder"), documentObject.User, year.Id);
                            month.Publish(documentObject.User);
                            umbraco.library.PublishSingleNode(month.Id);
                        }

                        // Check if day exists   
                        Document day = null;
                        foreach (umbraco.BusinessLogic.console.IconI i in month.Children)
                        {
                            if (i.Text == refNr[2])
                            {
                                day = new Document(i.Id);
                                break;
                            }
                        }
                        if (day == null)
                        {
                            day = Document.MakeNew(refNr[2], DocumentType.GetByAlias("umbracoBlogDateFolder"), documentObject.User, month.Id);
                            day.Publish(documentObject.User);
                            umbraco.library.PublishSingleNode(day.Id);
                        }

                        documentObject.Move(day.Id);
                    }

                }

                return true;

            }
            else
                return false;
        }   
 

    }
}

Is it possible that it doesn't work when just changing the aliases and types like 'umbracoBlogPost' or umbracoBlogDateFolder'? Or do I need to make some more changes?
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.