I'm having trouble getting properties names, and not aliases, from nodes in C#.
I'm using node factory to get a node from its id. Then I can iterate its properties and get value and alias. But how can I get the name of the properties? These are human readable, so I'd like to use them in a table, like so:
propname1 = propvalue1 propname2 = propvalue2
The big picture is to list search results. I'm getting the result.id and using it to get the node's properties.
var umbNode = new umbraco.presentation.nodeFactory.Node(result.Id);
string propValue = umbNode.GetProperty("propertyAlias1").Value;
But, since you're already specifying a string with the property alias, maybe you mean that you just want a list of properties and their values?
This should work:
var properties = umbNode.getProperties; foreach (var property in properties)
{
var name = property.PropertyType.Alias;
var value = property.Value;
// do something
}
My compiler output shows that I'm loading all dlls fine. I'm writing an ashx in umbraco's root, so all \bin assemblies are being loaded.But I have also now added <@Assembly> directives to be sure.
I can only see getProperties on umbraco.cms.businesslogic.web.Document, and PropertyType on umbraco.cms.businesslogic.property.
Nothing on Nodes... I can't see umbraco.presentation.nodeFactory.Property.PropertyType... nor Node.GetProperties, just Node.Properties. And .Properties returns nodeFactory.Property which doesn't access the property name. Is there a cast or queryinterface I can do?
That's my original problem. I can only get the Alias which is really a shorthand version of the property name. I need the name to show the user in a list of results from a search. Do I have to use Documents (I was avoiding this since I saw comments about performance).
In order to get the description that you've set on the docType (as opposed to the alias), you'd have to access the document type, which means a hit to the database, you should probably cache your macro if this gets used a lot:
var docType = DocumentType.GetByAlias(umbNode.NodeTypeAlias);
foreach (var propertyType in docType.PropertyTypes)
{
var propName = propertyType.Name;
var propValue = umbNode.GetProperty(propertyType.Alias).Value;
}
C# - list node's properties names and values
Hi there.
I'm having trouble getting properties names, and not aliases, from nodes in C#.
I'm using node factory to get a node from its id. Then I can iterate its properties and get value and alias. But how can I get the name of the properties? These are human readable, so I'd like to use them in a table, like so:
propname1 = propvalue1
propname2 = propvalue2
The big picture is to list search results. I'm getting the result.id and using it to get the node's properties.
Any advice on how to do this?
Thanks,
Duarte
Just use:
But, since you're already specifying a string with the property alias, maybe you mean that you just want a list of properties and their values?
This should work:
Hi Sebastiaan.
I don't see the getProperties method nor property.PropertyType...
I'm on 4.5.1.
I have a reference to umbraco and umbraco.presentation.nodeFactory. Any idea why?
Duarte
Try adding the cms.dll to your references and in your usings add umbraco.cms.businesslogic and umbraco.cms.businesslogic.web.
My compiler output shows that I'm loading all dlls fine. I'm writing an ashx in umbraco's root, so all \bin assemblies are being loaded.But I have also now added <@Assembly> directives to be sure.
I can only see getProperties on umbraco.cms.businesslogic.web.Document, and PropertyType on umbraco.cms.businesslogic.property.
Nothing on Nodes... I can't see umbraco.presentation.nodeFactory.Property.PropertyType... nor Node.GetProperties, just Node.Properties. And .Properties returns nodeFactory.Property which doesn't access the property name. Is there a cast or queryinterface I can do?
Duarte
Oh I'm sorry, you're working with the nodeFactory! I was working with the umbraco Document object.
The properties should be available like this (using umbraco.presentation.nodeFactory):
;)
ok, so now back to the start... :)
That's my original problem. I can only get the Alias which is really a shorthand version of the property name. I need the name to show the user in a list of results from a search. Do I have to use Documents (I was avoiding this since I saw comments about performance).
Thanks for your patience.
Duarte
Right, no problem we're getting there!
In order to get the description that you've set on the docType (as opposed to the alias), you'd have to access the document type, which means a hit to the database, you should probably cache your macro if this gets used a lot:
Ok. So now I'm thinking I should go the xml route... So... with result.id I can use GetXmlNodeById, and access all properties names?
Duarte
In XSLT you can simply do something like:
Of course, instead of $currentPage, you can put the node in there that you go through GetXmlNodeById.
Old post but i'm trying to make a object generator for Umbraco and i need to find the c# type of a PropertyType. Where can i find those?
is working on a reply...