Copied to clipboard

Flag this post as spam?

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


  • Asif Malik 203 posts 339 karma points
    Dec 13, 2010 @ 20:21
    Asif Malik
    0

    Umbraco backoffice preview function

    Hi all, i am trying to get the Preview function to work inthe Umbraco BackOffice. I am currently using umbraco 4.0.4.2 and was hoping someone could comment on what i am trying to do.

    Bascially the preview function works for <umbraco:Item 's in the template files. In my XSLT and user controls it doesnt. I have created a variable and set its value to either a copy of the currentPage or it goes off to a custom xslt extension


    <xsl:variable name="versionedPageRaw">
        <xsl:choose>
            <xsl:when test="string-length($umbVersion) != 0">
                <xsl:copy-of select="WebFunctions:getVersionedPage($currentPage/@id)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy-of select="$currentPage"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="versionedPage" select="msxml:node-set($versionedPageRaw)/node" />

     

    My getVersionedPage function is below and was hoping someone could let me know if there is anything wrong with what i am doing.

            public static XPathNodeIterator getVersionedPage ( int rootNodeId )
            {

                XmlDocument xmlDoc = new XmlDocument ( );
                XmlElement rootXmlNode = xmlDoc.CreateElement ( "node" );

                xmlDoc.AppendChild ( getNodeRecursively ( rootNodeId, rootXmlNode, ref xmlDoc ) );

                XPathNodeIterator myIterator = null;

                myIterator = xmlDoc.CreateNavigator ( ).Select ( "/" );

                return myIterator;

            }


            private static XmlElement createNodeNode ( XmlElement elemXmlNode, Document document )
            {
                elemXmlNode.SetAttribute ( "id", document.Id.ToString ( ) );
                elemXmlNode.SetAttribute ( "version", document.Version.ToString ( ) );
                try
                {
                    if ( document.Parent != null )
                        elemXmlNode.SetAttribute ( "parentID", document.Parent.Id.ToString ( ) );
                }
                catch ( Exception ex )
                {
                    elemXmlNode.SetAttribute ( "parentID", "-1" );
                }
                elemXmlNode.SetAttribute ( "level", document.Level.ToString ( ) );
                elemXmlNode.SetAttribute ( "writerID", document.Writer.Id.ToString ( ) );
                elemXmlNode.SetAttribute ( "creatorID", document.Creator.Id.ToString ( ) );
                elemXmlNode.SetAttribute ( "nodeType", document.ContentType.Id.ToString() );
                elemXmlNode.SetAttribute ( "template", document.Template.ToString ( ) );
                elemXmlNode.SetAttribute ( "sortOrder", document.sortOrder.ToString ( ) );
                elemXmlNode.SetAttribute ( "createDate", document.CreateDateTime.ToString ( "yyyy-MM-ddTHH:mm:ss" ) );
                elemXmlNode.SetAttribute ( "updateDate", document.UpdateDate.ToString ( "yyyy-MM-ddTHH:mm:ss" ) );
                elemXmlNode.SetAttribute ( "nodeName", document.Text );
                elemXmlNode.SetAttribute ( "urlName", url.FormatUrl ( document.Text.ToLower ( ) ) );
                elemXmlNode.SetAttribute ( "writerName", document.Writer.Name );
                elemXmlNode.SetAttribute ( "creatorName", document.Creator.Name );

                elemXmlNode.SetAttribute ( "nodeTypeAlias", document.ContentType.Alias );
                elemXmlNode.SetAttribute ( "path", document.Path );

                return elemXmlNode;
            }

            private static XmlElement createDataNode ( XmlElement elemDataNode, Property property )
            {
                try
                {
                    elemDataNode.SetAttribute ( "alias", property.PropertyType.Alias );
                    elemDataNode.InnerText = ( property.Value.ToString ( ) );
                }
                catch ( Exception ex )
                {
                }

                return elemDataNode;
            }

            private static XmlElement getNodeRecursively ( int nodeId, XmlElement thisXmlNode, ref XmlDocument xmlDoc )
            {
                Document document = new Document ( nodeId );

                thisXmlNode = createNodeNode ( thisXmlNode, document );
                foreach ( Property property in document.getProperties )
                {
                    XmlElement xmlDataNode = xmlDoc.CreateElement ( "data" );
                    thisXmlNode.AppendChild ( createDataNode ( xmlDataNode, property ) );
                }

                try
                {

                    if ( document.Children.Length > 0 )
                    {

                        foreach ( Document currentDocument in document.Children )
                        {
                            XmlElement childElemXmlNode = xmlDoc.CreateElement ( "node" );
                            childElemXmlNode = getNodeRecursively ( currentDocument.Id, childElemXmlNode, ref xmlDoc );

                            thisXmlNode.AppendChild ( childElemXmlNode );
                        }
                    }
                }
                catch ( Exception ex )
                {
                }
                return thisXmlNode;
            }

  • Asif Malik 203 posts 339 karma points
    Dec 13, 2010 @ 20:21
    Asif Malik
    0

    Missed out the umbVersion varibale ...

    <xsl:variable name="umbVersion" select="umbraco.library:RequestQueryString('umbVersion')"/>

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Dec 13, 2010 @ 22:11
    Aaron Powell
    0

    Why don't you upgrade to Umbraco 4.5.2, it has a built-in working preview.

  • Asif Malik 203 posts 339 karma points
    Dec 14, 2010 @ 09:40
    Asif Malik
    0

    Unfortunately we are running a Windows 2003 server with only .net2.0. I am trying to get us to upgrade to windows 2008 with .net4.0 but need an immediate solution.

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Dec 14, 2010 @ 10:06
    Aaron Powell
    0

    Then use the .NET 3.5 version and bin deploy the .NET 3.5 assemblies (System.Core, System.Xml.Linq and a few others).

    .NET 3.5 is CLR 2 still

  • Asif Malik 203 posts 339 karma points
    Dec 14, 2010 @ 10:29
    Asif Malik
    0

    Ok I wilol give this a go and update this post later on.

    Thanks for your help Slace

  • Asif Malik 203 posts 339 karma points
    Dec 14, 2010 @ 12:37
    Asif Malik
    0

    I am having a bit of a problem in getting the trees to display in all sections. Can you give me a better idea of all the extar assemblies i need to include

    Thanks

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Dec 14, 2010 @ 12:47
    Aaron Powell
    0

    System.Web.Extensions, System.Web.Abstractions, you'll need them, can't think of any more.

    Just install .NET 3.5, .NET 2.0 is pretty much EoL from MS anyway: http://support.microsoft.com/lifecycle/?LN=en-au&x=12&y=6&p1=8291

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies