I have created a class and using this class to fetch node information. I am able to get node name and node it but not able to get url or nice url of the node.
var node = new Node(item.Id);
pageName = item.Name;
item.Id url = node.Url;
You are using NodeFactory, and I think that might be tripping you up. Try using an Enumerable of PublishedContent instead, and see if you have access to the Url property on those. This is how you would
var root = Umbraco.TypedContentAtRoot().First();
var children = root.Children;
foreach (var child in children)
{
var pageName = child.Name;
var pageUrl = child.Url;
}
It depends a bit on where you are calling your class from, but i would be tempted to make this an extension method of the UmbracoHelper class and then you will have all the references you need to make these calls. so if you make it a static class and change the function to look like this:
public static GetPendingItemList(this UmbracoHelper umbraco)
{
....
var rootNodes = umbraco.TypedContentAtRoot();
}
you can get the root but again if this is called from a template or partial for a page, adding an Extension to IPublishedContent might be better as you can then reliably get the root node for a page (you site might have multiple roots, so you can't reliy on .First() on the TypedContentAtRoot() call.
public static GetPendingItemList(this IPublishedContent item)
{
var root = content.Site();
}
Not able to get Url of the page
I have created a class and using this class to fetch node information. I am able to get node name and node it but not able to get url or nice url of the node.
Fetching node url giving me exception.
Please suggest me how can i get the url
Thanks
Also tried this
var aa = umbraco.library.NiceUrl(Id);
But giving me null exception.
This post suggests that maybe you didn't published your node.
https://stackoverflow.com/questions/13394685/argumentnullexception-exception-with-node-niceurl-url-when-in-beginrequest-eve
I published node many times
An other clue could be the answer validated on this post: https://our.umbraco.org/forum/developers/api-questions/28787-NiceUrl-returns-a-instead-of-the-correct-URL
Maybe your UmbracoContext.Current is null ?
Yes Ali Z UmbracoContext.Current is null How can i resolve this, any clue?
The solution proposed doesn't work ?
Giving me this error
Context would help in understanding where it all goes wrong for you.
Could you try debugging the foreach loop, with these two lines on top:
Before you init a new node. Check their Values.
Hi Kristoffer
I have addedscreen shot above while debug,
And this code works fine but does not provide url of the page
You are using NodeFactory, and I think that might be tripping you up. Try using an Enumerable of PublishedContent instead, and see if you have access to the Url property on those. This is how you would
I am trying this but
why it is showing namespace error
Try initilaizing a umbracohelper if you dont have access to one.
Hi Kistoffer
Umbraco.TypedContentAtRoot() is not recognized. Am I missing something added namespace umbraco too.
Thanks
Hi Manish
It depends a bit on where you are calling your class from, but i would be tempted to make this an extension method of the UmbracoHelper class and then you will have all the references you need to make these calls. so if you make it a static class and change the function to look like this:
you can get the root but again if this is called from a template or partial for a page, adding an Extension to IPublishedContent might be better as you can then reliably get the root node for a page (you site might have multiple roots, so you can't reliy on .First() on the TypedContentAtRoot() call.
this will get you the root node of a site.
is working on a reply...