Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tobias 16 posts 61 karma points
    Dec 29, 2009 @ 19:19
    Tobias
    0

    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!

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Dec 29, 2009 @ 19:22
    Sebastiaan Janssen
    0

    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!

  • Tobias 16 posts 61 karma points
    Dec 29, 2009 @ 19:26
    Tobias
    0

    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.

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Dec 29, 2009 @ 19:41
    Sebastiaan Janssen
    0

    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. 

     

  • Tobias 16 posts 61 karma points
    Dec 29, 2009 @ 19:52
    Tobias
    0

    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.

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Dec 29, 2009 @ 20:09
    Sebastiaan Janssen
    0

    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!

  • Tobias 16 posts 61 karma points
    Dec 29, 2009 @ 20:29
    Tobias
    0

    Alright, will see if theres time for such a big solution. But thanks for your input, very helpful indeed!

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Dec 29, 2009 @ 22:15
    Morten Bock
    0

    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)

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Dec 29, 2009 @ 23:29
    Aaron Powell
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft