Thanks for the reply. I have read through the other thread (Didn't even remember writing my own posts!) and it threw some light on the situation, however I should say that I am trying to access the new document from a completely different page. According to the post you linked me to, that shouldnt cause a problem:
So doing a Document.Publish() in some server side code, like in a usercontrol or something like that, and then showing a page that contains xslt macros, shouldn't cause any problems
Here is exactly what I am doing:
on the document "createnewnode" I have a usercontrol with the following code:
The count property of getNodes is 0 after running the create document code. Only after I go to localhost/umbraco/dialogs/republish.aspx?xml=true or add the following code, does it find the actual nodes:
You are publishing the document before setting the properties in your code, which means the property values are not saved to the database. This again means that the xml node will have no data in the x property, and your XPath statement will not select anything.
And you should be good to go. The reason it works this way is that doc.Publish saves the document in the current state to the DB and marks it as published, and the library.UpdateDocumentCache() takes the published content in DB and updates the XML cache.
Haha, yep that did it! So do I need to republish a node every time I change one of it's properties for it to be fully propagated to the database and xml?
If you look at the samples floating around you'll see that it is now generally advised that you use the asp.net membership-, role- and profileproviders to interact with the members in the member section. If you're only working with the members as normal membership users you can use the methods available in the .NET System.Web.Security.Membership class, and if you need to access and modify the properties set up with the Member type editor in the Umbraco backend you'll need to use the System.Web.Profile.ProfileBase class.
Remember that the names of the profile properties used in your web.config file, has to be the same as the aliases of the properties you configure for your member type in Umbraco.
New document xml not updating
Hi all,
After creating a new document according to the reference doc below:
http://our.umbraco.org/wiki/reference/api-cheatsheet/publishing-and-republishing
and publishing / updating the xml with the following code:
//Get the document by it's ID
Document d = new Document(1234);
//Mark it ready for publishing
d.Publish(new umbraco.BusinessLogic.User(0));
//Tell the runtime to update the document cache
umbraco.library.UpdateDocumentCache(d.Id);
Then trying to access this new document results in the document not being found because it is not in the XML.
If I add the following code after the code above:
Server.ScriptTimeout = 100000; umbraco.cms.businesslogic.web.Document.RePublishAll(); umbraco.library.RefreshContent();
It works.
(Umbraco 4.7)
Any ideas why this is happening?
Thanks,
Max.
Yes - this is a well known behaviour.
You can find an explanation in my answer to this question:
http://our.umbraco.org/forum/developers/api-questions/18076-Creating-document-through-API-does-not-update-config-correct
Regards
Jesper Hauge
Thanks for the reply. I have read through the other thread (Didn't even remember writing my own posts!) and it threw some light on the situation, however I should say that I am trying to access the new document from a completely different page. According to the post you linked me to, that shouldnt cause a problem:
So doing a Document.Publish() in some server side code, like in a usercontrol or something like that, and then showing a page that contains xslt macros, shouldn't cause any problemsHere is exactly what I am doing:
on the document "createnewnode" I have a usercontrol with the following code:
Then later, the user navigates to a document called "getnodeinfo" with a usercontrol with the following code:
The count property of getNodes is 0 after running the create document code. Only after I go to localhost/umbraco/dialogs/republish.aspx?xml=true or add the following code, does it find the actual nodes:
The same behaviour occurs when running the equivalent XSLT query from an xslt macro...
Hi again Max,
You are publishing the document before setting the properties in your code, which means the property values are not saved to the database. This again means that the xml node will have no data in the x property, and your XPath statement will not select anything.
Change the usercontrol code to:
And you should be good to go. The reason it works this way is that doc.Publish saves the document in the current state to the DB and marks it as published, and the library.UpdateDocumentCache() takes the published content in DB and updates the XML cache.
Regards
Jesper Hauge
Haha, yep that did it! So do I need to republish a node every time I change one of it's properties for it to be fully propagated to the database and xml?
Yep, changing the property value of a document, triggers neither a Save nor a Publish operation. You're working on an in-memory object alone.
Regards
Jesper
I see. And what about members since they do not have a publish method?
If you look at the samples floating around you'll see that it is now generally advised that you use the asp.net membership-, role- and profileproviders to interact with the members in the member section. If you're only working with the members as normal membership users you can use the methods available in the .NET System.Web.Security.Membership class, and if you need to access and modify the properties set up with the Member type editor in the Umbraco backend you'll need to use the System.Web.Profile.ProfileBase class.
I put up an example of the configuration and code you could use for that here: https://bitbucket.org/jhauge/codesamples/src/tip/Umbraco/Membership/
Remember that the names of the profile properties used in your web.config file, has to be the same as the aliases of the properties you configure for your member type in Umbraco.
Regards
Jesper Hauge
is working on a reply...