Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Christopher W. Brandsdal 72 posts 133 karma points
    Nov 29, 2009 @ 17:09
    Christopher W. Brandsdal
    0

    Problems with duplicate folders in folder-tree

    Hi!

    I have made a short script based on the 'Blog 4 Umbraco' that creates folders based on date/month/year. But sometimes it duplicates the folders in the umbraco treeview. Why is that? I see that others have had the same problem also. see this link. It seems to work in iis7.5/win7, but not on iis7/win2k8. Both the duplicated folders has the same ID. Where do I start?

    Here is the code:

     using System;
    using System.Collections.Generic;
    using System.Web;
    using umbraco;
    using umbraco.cms.businesslogic.web;
    using umbraco.BusinessLogic;
    using umbraco.BusinessLogic.console;
    namespace KS
    {
        public class DateTimeFolder : umbraco.BusinessLogic.ApplicationBase
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="BlogDateFolder"/> class.
            /// </summary>
            public DateTimeFolder()
            {
                Document.New += new Document.NewEventHandler(Document_New);
            }
            /// <summary>
            /// Document_s the new.
            /// </summary>
            /// <param name="sender">The sender.</param>
            /// <param name="e">The <see cref="umbraco.cms.businesslogic.NewEventArgs"/> instance containing the event data.</param>
            void Document_New(Document sender, umbraco.cms.businesslogic.NewEventArgs e)
            {
                Document documentObject = sender;
                if (documentObject.ContentType.Alias == "DateTimeFolderItem")
                {
                    if (documentObject.Parent != null)
                    {
                        #region MonthFolder
                        if (new Document(documentObject.Parent.Id).ContentType.Alias == "MonthArchive")
                        {
                            string[] strArray = (documentObject.CreateDateTime.Year.ToString() + "-" + documentObject.CreateDateTime.Month.ToString()).Split("-".ToCharArray());
                            if (strArray.Length == 2)
                            {
                                Document document = null;
                                foreach (IconI ni in documentObject.Parent.Children)
                                {
                                    if (ni.Text == strArray[0])
                                    {
                                        document = new Document(ni.Id);
                                        break;
                                    }
                                }
                                if (document == null)
                                {
                                    document = Document.MakeNew(
                                        strArray[0],
                                        DocumentType.GetByAlias("DateTimeFolder"),
                                        documentObject.User,
                                        documentObject.Parent.Id);
                                    document.Publish(documentObject.User);
                                    library.UpdateDocumentCache(document.Id);
                                }
                                else
                                {
                                    Log.Add(LogTypes.Debug, documentObject.User, documentObject.Id, "executed - year not null");
                                }
                                Document document2 = null;
                                Document[] children = document.Children;
                                for (int i = 0; i < children.Length; i++)
                                {
                                    IconI ni2 = children[i];
                                    if (ni2.Text == strArray[1])
                                    {
                                        document2 = new Document(ni2.Id);
                                        break;
                                    }
                                }
                                if (document2 == null)
                                {
                                    document2 = Document.MakeNew(strArray[1], DocumentType.GetByAlias("DateTimeFolder"), documentObject.User, document.Id);
                                    document2.Publish(documentObject.User);
                                    library.UpdateDocumentCache(document2.Id);
                                }
                                else
                                {
                                    Log.Add(LogTypes.Debug, documentObject.User, documentObject.Id, "executed - month not null");
                                }
                                documentObject.Move(document2.Id);
                            }
                        }
                        #endregion
                    }
                }
            }
        }
    }
  • Christopher W. Brandsdal 72 posts 133 karma points
    Nov 30, 2009 @ 21:43
    Christopher W. Brandsdal
    0

    This is so strange. There seems to be no logic to it. Sometimes it actually displays it correct in the same solution.. One website works just perfect, and another one just gives me problems. The both use the same copy of dll's, and the same iis setup.

  • Dean 2 posts 22 karma points
    May 04, 2010 @ 12:53
    Dean
    0

    <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:595.3pt 841.9pt; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} -->

    I am also experiencing the same problem. I have created a document import tool which creates year and month folders which I’ve tried running several times. The issue seems to be intermittent; sometimes it works perfectly other times I get duplicate year and/or month folder entries. The weird thing is that the links in the tree open up the same database document (they point to the same document ID).

     

    Has anybody found a solution to this problem? I was relying on Document.MakeNew() working without problems in order to import my client’s old website data into their new Umbraco site.

Please Sign in or register to post replies

Write your reply to:

Draft