Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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;
Fetching node url giving me exception.
Please suggest me how can i get the url
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.
I published node many times
An other clue could be the answer validated on this post:
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 ?
if (UmbracoContext.Current == null)
UmbracoContext.Current = new UmbracoContext(HttpContext.Current);
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:
var pageName = item.Name;
var pageUrl = item.Url;
Before you init a new node. Check their Values.
I have addedscreen shot above while debug,
And this code works fine but does not provide url of the page
IContent content = `ApplicationContext.Current.Services.ContentService.GetById(item.Id);`
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;
I am trying this but
why it is showing namespace error
Try initilaizing a umbracohelper if you dont have access to one.
var helper = new UmbracoHelper();
var root = helper.TypedContentAtRoot();
Umbraco.TypedContentAtRoot() is not recognized. Am I missing something
added namespace umbraco too.
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();
this will get you the root node of a site.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted