Copied to clipboard

Flag this post as spam?

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


  • Peter Nielsen 159 posts 257 karma points
    Feb 26, 2011 @ 10:18
    Peter Nielsen
    0

    Creating a new Node with MakeNew() = two of the same node?!

    Hi,

    I have used Niels' example from the Umbraco TV, on how to create a new content node through a usercontrol.

    Here's my code:

            protected void Page_Load(object sender, EventArgs e) {
               
                DocumentType textPageType = DocumentType.GetByAlias("UserRos");
                Document newPage  = Document.MakeNew("Ros", textPageType, User.GetUser(2), 1171);
               
                newPage.getProperty("rosNavn").Value = "Peter Nielsen";
                newPage.getProperty("rosGade").Value = "P.P. Orums Gade";
                newPage.getProperty("rosHusnr").Value = "16, 3. tv";
               
                newPage.Publish(User.GetUser(0));
                umbraco.library.PublishSingleNode(newPage.Id);
               
            }

     

    It works an everything. But when i reload my node tree sometimes it has created two of the same node. With the same name, and the same id...

    Can somebody tell what I do wrong here? :-)

     

    Regards

    Peter

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Feb 26, 2011 @ 13:04
    Jeroen Breuer
    0

    Not sure if this is related, but I've also got some problems with double node names: http://our.umbraco.org/forum/core/general/17462-Missing-nodes-in-backend

    Jeroen

  • Kim Andersen 1447 posts 2197 karma points MVP
    Feb 26, 2011 @ 13:17
    Kim Andersen
    0

    Hi there Peter

    Could you try to change the last line from this:

    umbraco.library.PublishSingleNode(newPage.Id);

    to this:

    umbraco.library.UpdateDocumentCache(newPage.Id);

    /Kim A

  • Peter Nielsen 159 posts 257 karma points
    Feb 26, 2011 @ 19:38
    Peter Nielsen
    0

    Hi Kim,

    I tried that now. And tried with a if(!isPostBack) also... But nothing does the trick. I also tried to give the nodeName a unique name...

    Here's my code now:

            protected void Page_Load(object sender, EventArgs e) {
                if(!IsPostBack) {
                    DateTime time = DateTime.Now;
                    string format = "HHmmss";
                    string todayTime = time.ToString(format);
                   
                    DocumentType textPageType = DocumentType.GetByAlias("UserRos");
                    Document newPage  = Document.MakeNew("Ros_"+ todayTime, textPageType, User.GetUser(2), 1171);
               
                    newPage.getProperty("rosNavn").Value = "Peter Nielsen";
                    newPage.getProperty("rosGade").Value = "P.P. Orums Gade";
                    newPage.getProperty("rosHusnr").Value = "16, 3. tv";
               
                    newPage.Publish(User.GetUser(0));
                    umbraco.library.UpdateDocumentCache(newPage.Id);
                }
            }

     

    Any other suggestions? :-)

    /Peter

  • Kim Andersen 1447 posts 2197 karma points MVP
    Feb 26, 2011 @ 20:19
    Kim Andersen
    0

    Ahh okay, then I don't know what's going on. Sorry. Let's hope someone else have got a suggestion to whats wrong.

    /Kim A

  • Peter Nielsen 159 posts 257 karma points
    Feb 26, 2011 @ 21:19
    Peter Nielsen
    0

    Im doing this in the latest Juno version.. 4.6.1.. Dont know if it has anything to say?!

  • Peter Nielsen 159 posts 257 karma points
    Feb 28, 2011 @ 12:26
    Peter Nielsen
    0

    Okay, it's monday and we are all back in the office.

    Somebody who can give me some directions of what I am doing wrong here? :)

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 28, 2011 @ 12:28
    Bo Damgaard Mortensen
    0

    Hi pedn,

    Out of curiousity: are you running Umbraco on a MySQL server? :)

  • Peter Nielsen 159 posts 257 karma points
    Feb 28, 2011 @ 12:29
    Peter Nielsen
    0

    Hi Bo,

    Yes I am. Can that have anything to do with it? :-)

     

  • Peter Nielsen 159 posts 257 karma points
    Feb 28, 2011 @ 15:15
    Peter Nielsen
    0

    Okay,

    I checked the database, and the tables CMSCONTENT and CMSCONTENTXML only has the nodeId once per table.

    And if I check the App_Data/Umbraco.config, there is only one if each node aswell.

    However the CMSCONTENTVERSION table has several version of the nodes. But that counts for other nodes aswell, so I guess that is something with different versions of the same node or something like that. But when I see the VERSIONDATE in this table, it (2011-02-27 02:33:59). Can this be the problem.. maybe it created a create version and a publish version in the same second or something?!

    /Peter

  • Peter Nielsen 159 posts 257 karma points
    Feb 28, 2011 @ 16:53
    Peter Nielsen
    0

    So far I found out that it must be in this line the mistake is made.

    newPage.Publish(User.GetUser(0));

    If I quote this line out, I cant get Umbraco to make a dublicate node. But now a have a lot of nodes wich is not published, and I want them to be published...

    What to do?

  • Peter Nielsen 159 posts 257 karma points
    Feb 28, 2011 @ 19:02
    Peter Nielsen
    0

    Well.. It looks like I was right about the VERSIONDATE..

    Found this thread:

    http://our.umbraco.org/projects/collaboration/blog-4-umbraco/using-blog-4-umbraco/8901-Content-tree-lists-nodes-multiple-times

     

    People seems to experience the same thing with Juno..

  • Peter Nielsen 159 posts 257 karma points
    Feb 28, 2011 @ 20:08
    Peter Nielsen
    0

    Okay so now I solved my problem by creating pause in the code before it publish, so the VERSIONDATE is a second newer in the published version.

    So heres my new code:

     

            protected void Page_Load(object sender, EventArgs e) {
                if(!IsPostBack) {
                    DateTime time = DateTime.Now;
                    string format = "HHmmss";
                    string todayTime = time.ToString(format);
                   
                    DocumentType textPageType = DocumentType.GetByAlias("UserRos");
                    Document newPage  = Document.MakeNew("Ros_"+ todayTime, textPageType, User.GetUser(2), 1171);
               
                    newPage.getProperty("rosNavn").Value = "Peter Nielsen";
                   
                    Thread.Sleep(1500);
                   
                    newPage.Publish(User.GetUser(0));
                    //umbraco.library.PublishSingleNode(newPage.Id);
                    umbraco.library.UpdateDocumentCache(newPage.Id);

                    Response.Write("Site created: Ros_"+ todayTime + " with ID: "+ newPage.Id.ToString());
                }
            }

     

    This worked for me. I set this as solved, and Kim you helped me the most, so you get the karma points :-)

    Thanks again..

    /Peter

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 01, 2011 @ 08:02
    Kim Andersen
    0

    Well thank you sir. Actually I don't think that we are getting karma points when getting marked as the solution (only when people gives you a high five:) ), but thanks anyway.

    It's pretty strange that you have to insert a pause before publishing the node though. But if it works it's great right :)

    /Kim A

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies