I'am new to Umbraco. I would to dynamically fetch ID,created by,creation date etc properties which are dynamically created by Umbraco when a new node is created. I'am able to retrieve custom properties. Would like to know how do I fetch generic properties created by user and default properties that is dynamically generated by Umbraco like ID,created date,template etc.,
Have created .NET user control. Where i choose a parent node from content picker. On choosing parent node, custom properties are displayed with checkboxes. I would like to add generic and default properties too in this list. I'am using 6.1.6 v.
Hi Manasa,
Thanks for the code! I see you're using Node which is part of the Legacy API. I'd recommend using IPublishedContent instead.
As you're using a UserControl you should consider inheriting it from UmbracoWebControl (namespace: Umbraco.Web.UI.Controls).
public partial class YourUserControlName : UmbracoUserControl
This among other things will give you access to this.Umbraco (an UmbracoHelper class).
Then calling this.Umbraco.TypedContent(yourId) you can get a node as an IPublishedContent node.
Check out this example below as to how you could do what you do using the new API.
var specificNode = this.Umbraco.TypedContent(yourId);
var childrenOfSpecificNode = specificNode.Children;
var hasChildrenOfSpecificNode = childrenOfSpecificNode != null && childrenOfSpecificNode.Any();
if (hasChildrenOfSpecificNode) {
var firstChildOfSpecificNode = childrenOfSpecificNode.FirstOrDefault();
if (firstChildOfSpecificNode != null) {
this.CheckBoxList1.Items.Add("Id");
this.CheckBoxList1.Items.Add("CreateDate");
this.CheckBoxList1.Items.Add("CreatorName");
foreach (var properties in firstChildOfSpecificNode.Properties) {
this.CheckBoxList1.Items.Add(properties.Alias);
}
}
}
From what it looks like your code is trying to get the first child of a specific node and loop through its properties. Which is what the code above does. Id, CreateDate & CreatorName are all strongly typed properties of the IPublishedContent class so there isn't a way to get them dynamically. I'd suggest if you wanted to get those you'd have to check for them like so.
I'm assuming you're working on a PostBack
var node = this.Umbraco.TypedContent(idOfNodeForUseOnPostBack);
switch (this.CheckBoxList1.SelectedValue) {
case "Id":
//get property from strongly typed
node.Id;
break;
case "CreateDate":
//get property from strongly typed
node.CreateDate;
case "CreatorName":
//get property from strongly typed
node.CreatorName;
break;
default:
//get property from
node.GetPropertyValue(this.CheckBoxList1.SelectedValue);
break;
}
You could probably improve it further by making Id, CreateDate & CreatorName constants so you don't repeat the strings.
Here if i select contacts as parent node, I get the properties of Anu.
Here user selects properties he want to display.(firstname,ID,lastname)
Next he has a save button. On click of this button dropdown list with A,B etc is displayed. If user selects A, and clicks on display
properties(firstname,ID,lastname) along with their values of anu and angel should be displayed in gridview. If user selects B from dropdown, should display bharath and bargavi with their properties selected from dropdownlist.
To retrieve generic properties and default properties
Hi,
Can anyone guide me how to retrieve dgeneric and default properties dynamically?
Thanks
Hey Manasa,
Which properties do you need to get and how (XSLT, DynamicNode, IContent, etc)?
Thanks,
Jamie
Hey Jamie,
I'am new to Umbraco. I would to dynamically fetch ID,created by,creation date etc properties which are dynamically created by Umbraco when a new node is created. I'am able to retrieve custom properties. Would like to know how do I fetch generic properties created by user and default properties that is dynamically generated by Umbraco like ID,created date,template etc.,
Have created .NET user control. Where i choose a parent node from content picker. On choosing parent node, custom properties are displayed with checkboxes. I would like to add generic and default properties too in this list. I'am using 6.1.6 v.
Thanks,
Manasa
Hey Jamie,
using xml file would be preferable i guess?
Thanks,
Manasa
Hi Manasa,
If you're using a .net user control I would not recommend XML as this is better used with XSLT.
How are you currently getting the custom properties? Could you share a code snippet?
Thanks,
Jamie
Hey Jamie,
foreach (Node a in specificNode.Children)
{
if (a.Children.Count != 0)
{
foreach (Node b in a.ChildrenAsList)
{
if (x == 0)
{
if (b.PropertiesAsList.Count != 0)
{
CheckBoxList1.Items.Clear();
foreach (var c in b.PropertiesAsList)
{
CheckBoxList1.Items.Add(c.Alias);
}
x=1;
}
}
Hi Manasa,
Thanks for the code! I see you're using Node which is part of the Legacy API. I'd recommend using
IPublishedContent
instead.As you're using a UserControl you should consider inheriting it from
UmbracoWebControl
(namespace:Umbraco.Web.UI.Controls
).This among other things will give you access to
this.Umbraco
(anUmbracoHelper
class).Then calling
this.Umbraco.TypedContent(yourId)
you can get a node as anIPublishedContent
node.Check out this example below as to how you could do what you do using the new API.
From what it looks like your code is trying to get the first child of a specific node and loop through its properties. Which is what the code above does. Id, CreateDate & CreatorName are all strongly typed properties of the IPublishedContent class so there isn't a way to get them dynamically. I'd suggest if you wanted to get those you'd have to check for them like so.
I'm assuming you're working on a PostBack
You could probably improve it further by making Id, CreateDate & CreatorName constants so you don't repeat the strings.
Does that answer your question?
Hey Jamie,
Thanks for the needful help.. Yipee !! it solved my problem.:)
How can I retrieve values from properties I select from checkboxes and display in gridview? I'am stuck here :(
1. Initially I select a parent Node.
2.Secondly, display the properties of child nodes.
3.Next I select a childnode.
4.On display button, I wanna display properties selected by user and the grandchildren nodes in gridview.
I'am stuck in 4th step. Please guide me
Thanks
Manasa
Hey Manasa,
So as I understand it you want to display only the checked properties of the child node you've selected?
Or the checked properties of that child node's children?
Thanks,
Jamie
Checked properties of that child node's children - Jamie :)
Contacts
A
Anu
Angel
B
Bharath
Bargavi
Here if i select contacts as parent node, I get the properties of Anu.
Here user selects properties he want to display.(firstname,ID,lastname)
Next he has a save button. On click of this button dropdown list with A,B etc is displayed. If user selects A, and clicks on display
properties(firstname,ID,lastname) along with their values of anu and angel should be displayed in gridview. If user selects B from dropdown, should display bharath and bargavi with their properties selected from dropdownlist.
Thanks
Manasa
Sounds like you need a Current Users control which is separate to the users and then it will be used to bind the current users.
It might be easier do this with a Repeater web control. Because you'll have a varying number of columns.
so...
To display the fields
Your list would be a
List<List<string>>
which seems a bit weird nut right now I can't thing of anything which would allow the degree of flexability...Although I'll admit I'm a bit rusty with Web Forms.
You may also want to check out this link too. Which uses GridViews with dynamic columns.
Thanks a lot Jamie :)
No problem, my pleasure! If this answered your question please mark it as the answer. :)
is working on a reply...