Im currently trying to create a solution for a node to work with preview while it has a .Net usercontrol on it. This usercontrol needs to be able to find the node-ID of the content which it previews.
My question is: is there any way to find the node being previewed (with the changed values of course) from the .NET side? I can see the "?umbVersion=1480d1d3-da78-4461-947e-3c50f61ffbc8" etc being applied, can this be used in some way?
Yep, right before '?umbVersion" there's something like 1055.aspx. Where 1055 would be the nodeId of the node you're previewing. That should do the trick!
Ye, but the problem with that is that when I get it with that Id then I get the published content for that node and not the updated (just saved) content. When making the preview the customers would like to see what their soon-to-be update would look like. Hope you understand what I mean.
I understand. But that was not your question... ;-)
As far as I've always understood: the preview works fine if you do not use custom user controls.
You could write your user controls in such a way that it will take the unpublished content from the database when the "umbVersion" querystring is present, and when it's not there, it can just use the published content. But I don't know if you'd want to go that far.
Hehe, well, I wish there was any provisioning for that. But I don't think there is! You might have to really get your hands dirty and get the data from the database. You'll have to join cmsContentVersion with umbracoDocument and cmsPropertyData.
If you really want to do it well, you could probably make it very generic and then share the source code so it can hopefully be included in Umbraco itself. However, as it's not been included before, I fear that there are some difficult hurdles that you'd have to take.
As Morten pointed out the Document API is where you want to be heading, and passing in the ID of the node you want (best way to get that is UmbracoContext.Current.PageId) will return you the most recent version of that node, published or unpublished.
You can optionally pass the version GUID into the constructor along with the ID, which will load a particular version explicitly (useful if you're dealing with audit-trail preview).
Ultimately you'll have code in your user control which looks like this:
if(!string.IsNullOrEmpty(Request.QueryString["umbVersion"])) { var doc = new Document(UmbracoContext.Current.PageId.Value); // do whatever with the document } else { var node = new Node(UmbracoContext.Current.PageId.Value); // do whatever with the node }
But personally I prefer to make a wrapper class and a data service which is abstracted away so I would just query the data service and it decides if I get the published or unpublished version back.
Preview and .NET
Im currently trying to create a solution for a node to work with preview while it has a .Net usercontrol on it. This usercontrol needs to be able to find the node-ID of the content which it previews.
My question is: is there any way to find the node being previewed (with the changed values of course) from the .NET side?
I can see the "?umbVersion=1480d1d3-da78-4461-947e-3c50f61ffbc8" etc being applied, can this be used in some way?
Thanks for any help!
Yep, right before '?umbVersion" there's something like 1055.aspx. Where 1055 would be the nodeId of the node you're previewing. That should do the trick!
Ye, but the problem with that is that when I get it with that Id then I get the published content for that node and not the updated (just saved) content. When making the preview the customers would like to see what their soon-to-be update would look like. Hope you understand what I mean.
I understand. But that was not your question... ;-)
As far as I've always understood: the preview works fine if you do not use custom user controls.
You could write your user controls in such a way that it will take the unpublished content from the database when the "umbVersion" querystring is present, and when it's not there, it can just use the published content. But I don't know if you'd want to go that far.
Well, I might have to go that far =)
Is there any way to get unpublished nodes from the umbraco API? I cant seem to find any methods that seem appropriate.
Hehe, well, I wish there was any provisioning for that. But I don't think there is! You might have to really get your hands dirty and get the data from the database. You'll have to join cmsContentVersion with umbracoDocument and cmsPropertyData.
If you really want to do it well, you could probably make it very generic and then share the source code so it can hopefully be included in Umbraco itself. However, as it's not been included before, I fear that there are some difficult hurdles that you'd have to take.
I'd love to hear about your progress though!
Alright, will see if theres time for such a big solution. But thanks for your input, very helpful indeed!
Couldn't you just get the unpublished version using the Document class?
Something like
Document doc = new Document(1234);
label1.Text = doc.getProperty("propertyAliasHere").value;
I think there might even be a constructor overload that takes a version number (the guid from the url)
As Morten pointed out the Document API is where you want to be heading, and passing in the ID of the node you want (best way to get that is UmbracoContext.Current.PageId) will return you the most recent version of that node, published or unpublished.
You can optionally pass the version GUID into the constructor along with the ID, which will load a particular version explicitly (useful if you're dealing with audit-trail preview).
Ultimately you'll have code in your user control which looks like this:
But personally I prefer to make a wrapper class and a data service which is abstracted away so I would just query the data service and it decides if I get the published or unpublished version back.
is working on a reply...