Annoying problem when creating documents from frontend usercontrol
Hi Umbracos (and happy birthday Umbraco! ;-))
I've been working with Umbraco for about half a year now and already released many solutions based on this brilliant CMS. My experience as a webdeveloper working with Umbraco is growing every day and I'm getting more and more into the API.
However.. there's one, single issue that I simply just can't find the solution to. When I make an ASP.NET UserControl to place on the frontend, to let the users create new documents/nodes in Umbraco it created the node twice! This happens on nearly all umbraco installation I've been working on since I started. The version I'm working with is 4.5.2 for both .NET 3.5 and 4.0. I had a peek into the database to find out if the node was actually created twice or if it was just a nodetree cache problem of some sort. To my surprice it does actually get created twice in the database like this (MySQL):
3208
0
0
96043dc4-61a2-4a9c-b914-ffc3728ab12c
16-02-2011_Name
NULL
NULL
2011-02-16 12:02:47
NULL
NULL
1
3208
1
0
1e0b2633-673c-491a-81b0-5569d6f86a22
16-02-2011_Name
NULL
NULL
2011-02-16 12:02:47
NULL
NULL
0
This is from the CMSDOCUMENT table by the way. As you can see, the first is not published (0) while the second is published.
When I publish a document from a UserControl I'm doing it this way:
Am I missing something here? Anyone else had this problem before? It's a bit hard to explain to cutomers why the content appears twice when you don't have a clue about it ;-)
I just tried to skip the umbraco.library.RefreshContent();, but that didn't work either. Also, I just installed a completely fresh copy of Umbraco JUNO and after the first document was created, it started to make duplicates again. It seems like I'm the only one having that problem ;-) This is the simple test I just did on the new Umbraco installation:
Also, if i'm looking at the content section in Umbraco, then create a new document from the webform, refresh the content tree, switch to i.e. the Settings section and back to the contenttree - the newly created documents name is duplicated after each other until I reload the nodes again (?) Like this:
Here I have switched back and forth between the Content section and the Settings section three times (as you can see, the name of the node(s?) is duplicated x 3.
I've been looking at the 4.6.2 changesets but failed to find the one (c3327b2d6a99) Niels wrote about on the workitem you linked to. Was just wondering if this fix is underway or if I'm just plain blind ;-)
Thanks again for your help! Appreciated!
/ Bo
Edit: turns out that I was just blind. Found the workitem, but I'll just use MSSQL for my future umbraco projects since it seem to solve the problem.
I'm having the same problem (I'm using mySql as database) - but it seems that a republish of the parentnode, and subnodes, fixes the double node issue.
It works like a charm, but i'm running into a problem where any unpublished documents that are scheduled to publish on a certain day/time, will be publieshed aswell :-/ Any workarounds for this?
Off the top of my head I would guess that the [document].ReleaseDate could be checked to see if it is to be published in the future, and that [document].ExpireDate could be checked to see if it has been unpublished. You should however make a loop on the subs of your parentnode, instead of using parentDocument.PublishWithSubs(new User(0));
so code would look something like this:
foreach (Document document in Document.GetChildrenForTree(parentId)) {
if (document.ReleaseDate is not to be published yet thene...)
Looping through the childnode collection was my first idea, but wouldn't it be the publishWithSubs() method that solves the issue? Could just do a check on the document.IsPublished() method, but I'm not sure if it works just by calling the Publish() method on the node. Seems to be the parent node that needs to be published with all the childnodes. I might aswell be very wrong about this ;-) I'm working on-site today so I can't test it yet, sadly.
Annoying problem when creating documents from frontend usercontrol
Hi Umbracos (and happy birthday Umbraco! ;-))
I've been working with Umbraco for about half a year now and already released many solutions based on this brilliant CMS. My experience as a webdeveloper working with Umbraco is growing every day and I'm getting more and more into the API.
However.. there's one, single issue that I simply just can't find the solution to. When I make an ASP.NET UserControl to place on the frontend, to let the users create new documents/nodes in Umbraco it created the node twice! This happens on nearly all umbraco installation I've been working on since I started. The version I'm working with is 4.5.2 for both .NET 3.5 and 4.0. I had a peek into the database to find out if the node was actually created twice or if it was just a nodetree cache problem of some sort. To my surprice it does actually get created twice in the database like this (MySQL):
This is from the CMSDOCUMENT table by the way. As you can see, the first is not published (0) while the second is published.
When I publish a document from a UserControl I'm doing it this way:
Am I missing something here? Anyone else had this problem before? It's a bit hard to explain to cutomers why the content appears twice when you don't have a clue about it ;-)
Any help is greatly appreciated!
Thanks in advance.
All the best,
Bo
Hi Bo,
A way to create/publish new nodes that's always worked for me is:
I hope this helps.
David
Hi David,
Thanks for your input :-)
I just tried to skip the umbraco.library.RefreshContent();, but that didn't work either. Also, I just installed a completely fresh copy of Umbraco JUNO and after the first document was created, it started to make duplicates again. It seems like I'm the only one having that problem ;-) This is the simple test I just did on the new Umbraco installation:
Frontend:
And the codebehind:
What exactly am I doing wrong?
All the best,
Bo
Also, if i'm looking at the content section in Umbraco, then create a new document from the webform, refresh the content tree, switch to i.e. the Settings section and back to the contenttree - the newly created documents name is duplicated after each other until I reload the nodes again (?) Like this:
Here I have switched back and forth between the Content section and the Settings section three times (as you can see, the name of the node(s?) is duplicated x 3.
Something is wrong.. ;-)
Hi Bo,
It does not appear that you are doing anything incorrectly.
The problem may be related to this: http://umbraco.codeplex.com/workitem/29443.
It is also mentioned here: http://our.umbraco.org/projects/collaboration/blog-4-umbraco/using-blog-4-umbraco/8901-Content-tree-lists-nodes-multiple-times.
I don't know the current status of this. One answer may be to use SQL Server if possible.
Sorry I don't have a better answer for you.
David
Hi again David and thanks for your reply.
I've been looking at the 4.6.2 changesets but failed to find the one (c3327b2d6a99) Niels wrote about on the workitem you linked to. Was just wondering if this fix is underway or if I'm just plain blind ;-)
Thanks again for your help! Appreciated!
/ Bo
Edit: turns out that I was just blind. Found the workitem, but I'll just use MSSQL for my future umbraco projects since it seem to solve the problem.
Hi Bo,
I'm having the same problem (I'm using mySql as database) - but it seems that a republish of the parentnode, and subnodes, fixes the double node issue.
Found the tip with republishing here: http://our.umbraco.org/forum/developers/api-questions/13132-Nodes-listing-two-times-in-node-tree
code should look something like this
sb.Append("Republishing parentfolder with subnodes");
sb.Append("Republishing done");
Update: seems a RefreshContent() is needed after re-publish for Umbraco not to puke
umbraco.library.RefreshContent();
/Søren
Hi Søren,
Thanks a lot ! Hero of the day! ;-)
It works like a charm, but i'm running into a problem where any unpublished documents that are scheduled to publish on a certain day/time, will be publieshed aswell :-/ Any workarounds for this?
Thanks again!
/ Bo
Hi Bo,
Great to hear it workd for you too :)
Off the top of my head I would guess that the [document].ReleaseDate could be checked to see if it is to be published in the future, and that [document].ExpireDate could be checked to see if it has been unpublished. You should however make a loop on the subs of your parentnode, instead of using parentDocument.PublishWithSubs(new User(0));
so code would look something like this:
if (document.ReleaseDate is not to be published yet thene...)
else { document.Publish(new User(0)); }
Do let me know if it works out for you :)
Hey Søren,
Looping through the childnode collection was my first idea, but wouldn't it be the publishWithSubs() method that solves the issue? Could just do a check on the document.IsPublished() method, but I'm not sure if it works just by calling the Publish() method on the node. Seems to be the parent node that needs to be published with all the childnodes. I might aswell be very wrong about this ;-) I'm working on-site today so I can't test it yet, sadly.
Thanks again!
- Bo
is working on a reply...