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.
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.
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>
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?
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?
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>
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?
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 :).
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?
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.
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.
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.
Have you found any solution? I came across the same issue and can't find the way to redirect to a media file.
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.:
/Chriztian
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.
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
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.
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?
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 :).
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?
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 :)
Hi Dan did you have any luck with this?
Charles.
is working on a reply...