Copied to clipboard

Flag this post as spam?

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


  • wolfestone 89 posts 21 karma points
    Feb 02, 2009 @ 20:59
    wolfestone
    0

    Possible to modify umbracoRedirect to link to a file (media item?)

    I read through this thread: http://forum.umbraco.org/yafpostst5606Page-Redirecting.aspx
    which was really helpful in sorting out a redirect.

    I tried the code snippet there, and also have checked out the two redirect packages that were linked. (all of which worked fine for redirecting to another web page)

    I need to redirect a page to a media picker file (pdf), but I wasn't able to do this by substituting a media picker document type field for the content picker umbracoRedirect uses.

    Is there a simple way I can achieve this? I'm using a lightly modified runway dropdown navigation menu.

  • wolfestone 89 posts 21 karma points
    Feb 10, 2009 @ 00:26
    wolfestone
    0

    I should add that the two redirect packages I downloaded both appear to be aspx/c# with dlls, which is beyond my skill level to edit unfortunately.

    Edit: I believe it's not possible to use response.redirect to open a file in a new window, so I'm guessing I need to handle this in the xslt for the navigation menu instead.



  • Den Gordo 29 posts 49 karma points
    Jan 02, 2013 @ 18:08
    Den Gordo
    0

    Have you found any solution? I came across the same issue and can't find the way to redirect to a media file.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jan 03, 2013 @ 10:04
    Chriztian Steinmeier
    0

    Hi Den,

    I'd suggest you take a look at the Macro Service package and create a macro that takes a media item ID as input and tries to force a download.

    You're probably using a dummy document type of some sorts, for including this in navigation, so you probably have a downloadFile property (Media Picker) on that document type as well - just check for that in the navigation XSLT and create the llink to the macro service you setup instead, e.g.:

    <xsl:for-each select="...">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <!-- If this should be a file download, override the href attribute --> <xsl:if test="normalize-space(downloadFile)"> <xsl:attribute name="href">/macro/servefile?file=<xsl:value-of select="downloadFile" /></xsl:attribute> </xsl:if>
                <xsl:value-of select="@nodeName" />
            </a>
        </li>
    </xsl:for-each>

    /Chriztian

  • Den Gordo 29 posts 49 karma points
    Jan 03, 2013 @ 10:34
    Den Gordo
    0

    Hi Chriztian,

    Thanks for your comment. The idea is that the page can be accesed directly like /download-me/ and when the page is loaded the file download should start or at least it should redirect to a media file, lets say to a pdf file. Is it something that can be done in XSLT?

    Regards Den.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jan 03, 2013 @ 10:40
    Chriztian Steinmeier
    0

    Hi again,

    Yes - you should be able to do that - the Macro Service should be able to do the download headers, and for the direct access URL, I'd go with a URL Rewrite - it sounds like you're only going to do a couple of files anyway, right?

    /Chriztian 

  • Charles Afford 1163 posts 1709 karma points
    Jan 03, 2013 @ 11:03
    Charles Afford
    0

    Hi,

    What is the end goal and where and how are you redirecting?  Is there a link on the page that a user clicks and gets re-directed or is it when somebody hits that page they get redirected to the media file?

    If you want to re-write a link to a file then get the file attributes using:

    <xsl:variable name="your name" select="umbraco.library:GetMedia(pass in media item,0)"></xsl:variable>
     <xsl:variable name="your var name" select="$yourname/umbracoFile"></xsl:variable> (this will be the url)

    do this for the other attributes.

    Construct an <a> tag using <a> <xsl:attribute name="url">pass in url </xsl:attribute>

    Hope this helps, 

    Charles.

  • Den Gordo 29 posts 49 karma points
    Jan 04, 2013 @ 14:51
    Den Gordo
    0

    Hi Charles,

    The goal is to have a page which, by entering the page either from a link or directly, will redirect to a media file (pdf). The idea is to have one link like (download-a-pdf) and editors can choose from the media picker which file will be loaded. How can I redirect from XSLT? Can I use a razor code in XSLT to create a function and then call it in XSLT code?

  • Charles Afford 1163 posts 1709 karma points
    Jan 04, 2013 @ 15:46
    Charles Afford
    0

    You dont really want to start mixing XSLT and razor together, i would not do that.

    If you look at my code above the "your var name" variable will be the relative path to the media item (so if you click that you will be taken to the media item)

    Thus if you put this in a <a href="your var name"> when a user clicks on this link they will be taken directly to that media item.

    Does that make sense?

    I will post some code for you tonight if you are still stuck :).

  • Den Gordo 29 posts 49 karma points
    Jan 04, 2013 @ 16:04
    Den Gordo
    0

    Hi Charles,

    Thanks for your efforts. But I don't need to create a link to the media item, because users may access the page directly from emails or other sources, so the only option is to get redirect to the media item automatically on page load. Let's say there is no links to that page at all, only a direct link, that you type in a browser, and buy entering the page you get redirected to the media item.

    Is there any function in starndart Umbraco librararies that can do redirects and can be accessed from XSLT?

  • Charles Afford 1163 posts 1709 karma points
    Jan 04, 2013 @ 20:47
    Charles Afford
    0

    Ok, well in that case something like this might help.  http://our.umbraco.org/projects/backoffice-extensions/permanent-redirect.  Otherwise you could create an extension method that gets the property value using the Umbraco API and this then gets returned into responce.redirect().  Although i am not sure how you would identify whether a user needs to be redirected, without passing a key value server-side by either query string or javascript/JSON.

    Page load

    {

    reponce.redirect(yourMethodThatReturnsAString());

    }

    Let me know what you think :)

  • Charles Afford 1163 posts 1709 karma points
    Jan 06, 2013 @ 14:05
    Charles Afford
    0

    Hi Dan did you have any luck with this?

    Charles.

Please Sign in or register to post replies

Write your reply to:

Draft