Copied to clipboard

Flag this post as spam?

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


  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Sep 22, 2009 @ 11:16
    Niels Hartvig
    4

    In v4 you can also use the contenttype element/control

    In Umbraco 4 we introduced the <umbraco:ContentType /> control so you can use that as well - for instance:

    <umbraco:ContentType runat="server" MimeType="text/xml"></umbraco:ContentType>

  • dandrayne 1138 posts 2262 karma points
    Sep 22, 2009 @ 11:40
    dandrayne
    1

    Nice!  is there a built-in control to change the filename presented in the "save as" dialogue box? 

  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Sep 22, 2009 @ 12:50
    Niels Hartvig
    2

    No, but a cool idea to add that as another attribute! Could you add to Codeplex?

  • dandrayne 1138 posts 2262 karma points
    Sep 22, 2009 @ 14:15
    dandrayne
    1

    Added to http://umbraco.codeplex.com/WorkItem/View.aspx?WorkItemId=24700

    It would be nice to be able to do this without using (even short snippets of) inline c# in templates.  Also would be a better separation of concerns, with no behavioural code in xsl.

    Cheers again
    Dan

  • Peter Cort Larsen 421 posts 1038 karma points
    Oct 08, 2009 @ 11:29
    Peter Cort Larsen
    0

    How do i use this?

  • Peter Cort Larsen 421 posts 1038 karma points
    Oct 08, 2009 @ 11:35
    Peter Cort Larsen
    0

    Is it possible to get the filename from the querystring?

  • dandrayne 1138 posts 2262 karma points
    Oct 10, 2009 @ 09:57
    dandrayne
    0

    Hi Peter

    For this package, you simply set the filename and MIME type once when you insert it in a template, then put your output xslt in the same template and when your user visits the page they'll be prompted to download the output of your xslt using the supplied filename and MIME type.

    I think for passing the filename via a querystring that the c# function in xslt is your best bet, see below (and http://our.umbraco.org/projects/change-output/general/4246-Also-possible-using-inline-script-in-xslt)

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:gecko="urn:gecko-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets gecko">
    <xsl:output method="text" omit-xml-declaration="yes"/>


    <msxml:script language="CSharp" implements-prefix="gecko">
    <msxml:assembly name="System.Web" />
    <msxml:using namespace="System.Web" />

    <![CDATA[
    public void changeOutPut(String ContentType, String FileName) {
    HttpContext.Current.Response.ContentType = ContentType;
    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + FileName);
    }
    ]]>

    </msxml:script>


    <xsl:param name="currentPage"/>

    <xsl:variable name="fileName">
    <xsl:choose>
    <xsl:when test="string-length(umbraco.library:Request('filename')) &gt; 0">
    <xsl:value-of select="umbraco.library:Request('filename')"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:text>defaultFilename.extension</xsl:text>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:template match="/">
    <xsl:value-of select="gecko:changeOutPut('text/csv',$fileName)" />
    </xsl:template>

    </xsl:stylesheet>

    Then just pass the filename via page.aspx?filename=whatever.csv

    Hope this helps,
    Dan

     

Please Sign in or register to post replies

Write your reply to:

Draft