Thanks for responding. I tried your code and I am still getting null back.
public static string GetLink(IContent item)
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
//Get URL for documents like PDF files
if (item.ContentType.Alias == "document")
{
return item.GetValue<string>("documentLink");
}
//Get the URL of published Content of a "unpublished" node
if (item.HasPublishedVersion && !item.Published)
{
var publishedVersion = ApplicationContext.Current.Services.ContentService.GetPublishedVersion(item);
var typedContentCurrentPublishedVersion = umbracoHelper.TypedContent(publishedVersion.Id);
return typedContentCurrentPublishedVersion.Url;
}
//Standard return URL
return umbracoHelper.NiceUrl(item.Id);
}
This line returns null: var typedContentCurrentPublishedVersion = umbracoHelper.TypedContent(publishedVersion.Id);
In the Code Documentation is written: Returns the content, or null of the content item is not in the cache.
I recently updated Umbraco to the newest version and I have the fear it's because of that. I already undo the to a older version but and I still got the null. The release might broke something, but i don't think so than everything else works fine.
EDIT
I am pretty sure it's not because of the update
I think with this code example I understand better your question.
Essentially I think you are saying... if the current version of the content item is not yet published - but there is a Previously published version - what is the url of that previously published version?
If you have the id of a content item, then Umbraco.TypedContent will retrieve whatever the current published version is in the form of an IPublishedContent object, and calling .Url will be that Published Url... however if that current item is UnPublished, then Umbraco.TypedContent will be null...
Essentially there isn't a way to find out what the Url 'was' of a previously version of a page, if that page is now unpublished.
I'm not sure of the context of what you are trying to achieve, but on a site, my company built, we had the notion of 'archived content' eg content that was published, but not accessed for a while was automatically 'unpublished' and stored in a flat database table, any future incoming requests for the 'unpublished' page was diverted to serve the archived version. The way we mapped the url to the archived version, was to tap into the Un-publishing event in Umbraco that fires just before something is Unpublished, and use that to find the Url it was published under, storing this in the archive....
Get URL of published version from node
Hello, I have a node which has a published version and is right now unpublished:
I would like to get the URL of the published version of this node.
I managed to get the published version with this line:
After that i tried to get the URL with this line:
This gives my back a "#" which happens (umbraco code documentation)
How can I get the Url of the published version from a node?
thanks in advance!
Hi Nikola
If you have the id of your content item then
This will always return the current published version's url, regardless if further 'saves' have been made since it was published.
regards
marc
Hello Marc,
Thanks for responding. I tried your code and I am still getting null back.
This line returns null:
var typedContentCurrentPublishedVersion = umbracoHelper.TypedContent(publishedVersion.Id);
In the Code Documentation is written:
Returns the content, or null of the content item is not in the cache.
I recently updated Umbraco to the newest version and I have the fear it's because of that. I already undo the to a older version but and I still got the null. The release might broke something, but i don't think so than everything else works fine.
EDIT I am pretty sure it's not because of the update
Thanks in regards!
Hi Nikola
I think with this code example I understand better your question.
Essentially I think you are saying... if the current version of the content item is not yet published - but there is a Previously published version - what is the url of that previously published version?
If you have the id of a content item, then Umbraco.TypedContent will retrieve whatever the current published version is in the form of an IPublishedContent object, and calling .Url will be that Published Url... however if that current item is UnPublished, then Umbraco.TypedContent will be null...
Essentially there isn't a way to find out what the Url 'was' of a previously version of a page, if that page is now unpublished.
I'm not sure of the context of what you are trying to achieve, but on a site, my company built, we had the notion of 'archived content' eg content that was published, but not accessed for a while was automatically 'unpublished' and stored in a flat database table, any future incoming requests for the 'unpublished' page was diverted to serve the archived version. The way we mapped the url to the archived version, was to tap into the Un-publishing event in Umbraco that fires just before something is Unpublished, and use that to find the Url it was published under, storing this in the archive....
is working on a reply...