How to access a custom property in a content Node from code
Hello
I added a property (alias = "rooms") to a document type on my umbraco website.Then I added a content node using this document type, filled the property, and I need to access it from my C# code (usercontrol for example). So I tried:
But It seems myNode.GetProperty("rooms") is null, even if the property is filled in the backoffice and the content node is published !
I don't understand since I thought I should use the Node class to access to the XML cache, containing the published nodes. But the informations of this node doesn't seem up-to-date (I tried to parse the 'Properties' field of myNode to see what's inside...). I tried to reload the cache (re-publishing the home content node, recycling the application pool, etc). Nothing changed.
By the way I'm using umbraco 3 (I can't upgrade...) but I think I'm missing something in my code, I can't see what.
1. Double check the alias of the "rooms" property on your document type and make sure you have it exactly the same as in your c# code - it is case sensitive so won't work if they don't match.
2. Try republishing your entire site (right click on the top level node and select "Republish entire site".
At least that's what I'm doing. We just have to keep in mind that when working with the Document object, every .getProperty("propertyAlias").Value is a database hit, so Node should be used for reading data when possible :-)
To Nigel : I checked the alias (in fact I already tried rooms, Rooms, ...) and republished the entire site. Nothing changed. Even if I recycle the application pool. I still have old informations in the object and I can't figure out why. The alias "rooms" doesn't even appear in the Properties collection of the object.
I'm not sure how the cache works in umbraco, but I noticed that when I publish the node in the backoffice, the cmsContentXml Table is updated, BUT the object's Properties collection is still up-to-date.
I finally figured out what was happening. It was a cache issue : the IIS process didn't have access to the umbraco.config file, so when I republished the site, the update couldn't be completed. If it can help someone...
How to access a custom property in a content Node from code
Hello
I added a property (alias = "rooms") to a document type on my umbraco website.Then I added a content node using this document type, filled the property, and I need to access it from my C# code (usercontrol for example).
So I tried:
Node myNode = new Node(1234);
string myPropertyValue = myNode.GetProperty("rooms").Value;
But It seems myNode.GetProperty("rooms") is null, even if the property is filled in the backoffice and the content node is published !
I don't understand since I thought I should use the Node class to access to the XML cache, containing the published nodes. But the informations of this node doesn't seem up-to-date (I tried to parse the 'Properties' field of myNode to see what's inside...). I tried to reload the cache (re-publishing the home content node, recycling the application pool, etc). Nothing changed.
By the way I'm using umbraco 3 (I can't upgrade...) but I think I'm missing something in my code, I can't see what.
Thanks in advance for you help.
Hi Carole
1. Double check the alias of the "rooms" property on your document type and make sure you have it exactly the same as in your c# code - it is case sensitive so won't work if they don't match.
2. Try republishing your entire site (right click on the top level node and select "Republish entire site".
Cheers, Nigel
Hi Carole,
Adding to Nigels post, I think it's generally a good practice to check for null values and empty string values when accessing a property. Like this:
At least that's what I'm doing. We just have to keep in mind that when working with the Document object, every .getProperty("propertyAlias").Value is a database hit, so Node should be used for reading data when possible :-)
Thanks to both of you for answering.
To Nigel : I checked the alias (in fact I already tried rooms, Rooms, ...) and republished the entire site. Nothing changed. Even if I recycle the application pool. I still have old informations in the object and I can't figure out why. The alias "rooms" doesn't even appear in the Properties collection of the object.
I'm not sure how the cache works in umbraco, but I noticed that when I publish the node in the backoffice, the cmsContentXml Table is updated, BUT the object's Properties collection is still up-to-date.
I finally figured out what was happening. It was a cache issue : the IIS process didn't have access to the umbraco.config file, so when I republished the site, the update couldn't be completed. If it can help someone...
Thanks for your help.
is working on a reply...