Copied to clipboard

Flag this post as spam?

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


  • Marius 22 posts 42 karma points
    Nov 26, 2009 @ 10:18
    Marius
    0

    best practice for listing download files

    Hi,

    What is best practice,  how do you do:

    Listing available files for download, in specific document type.

    For example I have a document type (page), which could have 1 to 5 (pdf or doc) files associated with it, and I want to make a "Download" section to list all these files.

    I'm thinking of

    1) document property as mediapicker datatype, but that would mean I must create up to 5 properties

    2) listing all media files available in specific media folder  (associated with page)

    What are other options?

    Marius

     

  • dandrayne 1138 posts 2262 karma points
    Nov 26, 2009 @ 10:39
    dandrayne
    0

    You could:

    • Use a "multiple media picker" (treemultipicker) on the document type
    • Your option 2, using a single mediapicker

    I tend to go with option 2.  Post back if you need a code sample for one of these options

    Dan

  • Marius 22 posts 42 karma points
    Nov 26, 2009 @ 11:10
    Marius
    0

    Thanks, dandrayne,

    yep, code examples are always usefull to learn and reuse. Experimenting now with "TreeMultiPicker", have you some xlst excerpt how do I list this tree files?

  • dandrayne 1138 posts 2262 karma points
    Nov 26, 2009 @ 11:30
    dandrayne
    0

    Ok - the following samples should work but are untested

    <!-- If using a treemultipicker - lefteris compatibility mode -->

    <xsl:if test="string($currentPage/data [@alias='documentList']) != ''">
    <ul class="nav">
    <xsl:variable name="documentNodeSet" select="$currentPage/data[@alias='documentList']"/>
    <xsl:for-each select="$documentNodeSet/descendant::node">
    <li>
    <a href="{umbraco.library:GetMedia(current(), 'false')/data [@alias='umbracoFile']}">
    <xsl:value-of select="umbraco.library:GetMedia(current(), 'false')/@nodeName" />
    </a>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>

     

    <!-- If using a mediapicker to select a whole folder  -->

    <xsl:variable name="mediaFolder" select="umbraco.library:GetMedia($currentPage/data [@alias='mediaPickerAlias'], 'true')" />
    <xsl:for-each select="$mediaFolder/node">
    <li>
    <a href="{current()/data [@alias='umbracoFile']}">
    <xsl:value-of select="current()/@nodeName" />
    </a>
    </li>
    </xsl:for-each>

    Dan

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Nov 26, 2009 @ 11:56
    Rasmus Berntsen
    0

    You could also use another option:

    Create two documenttypes - 1. DownloadArea and 2. DownloadItem. Create the DownloadArea in your content and create the DownloadItems below the Download Area:

    DownloadArea

    -DownloadItem

    -DownloadItem

    -DownloadItem

     

    DownloadItem should have an UploadField property.

     

    Create an xslt which lists all of the DownloadItems below the DownloadArea.

  • Marius 22 posts 42 karma points
    Nov 26, 2009 @ 12:12
    Marius
    0

    Yes, first example with only "Lefteris" mode work correctly.

    Big thanks, Dandrayne

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Nov 26, 2009 @ 12:13
    Rasmus Berntsen
    0

    ...That way you could also add specific download image, description etc. to each download item. :)

  • Marius 22 posts 42 karma points
    Nov 26, 2009 @ 12:19
    Marius
    0

    Thanks, Berntsen,

    that's an option, yes,

    Though I like Dandrayne solution more, because it's more flexible I think.

    Oh, man, clicked by mistake on Berntsen post as solved, sorry Dan..., I liked your tip.

     

  • dandrayne 1138 posts 2262 karma points
    Nov 26, 2009 @ 12:39
    dandrayne
    0

    Heh, no problem!

    You can also add new fields such as description ertc to files stored in the media library (check "media types" in the settings areas) and access them using GetMedia in the same way.  Combined with a multiple upload datatype it makes media management easier when kept in the media tree.

    Dan

  • BarneyHall 141 posts 210 karma points
    Nov 26, 2009 @ 14:21
    BarneyHall
    0

    Hello - this is a really helpful thread.

    Can anyone give a help on how to add a small gif "file" icon to any listed documents? Would be ace if this was dependant on the file type (i.e. .pdf .doc .mp3 etc) so that a different gif gets displayed according to the file being listed.

    I guess it can be done with XSLT but I'm very much a newb in that area.

    Thanks for any help offered,
    Barney

  • dandrayne 1138 posts 2262 karma points
    Nov 26, 2009 @ 14:58
    dandrayne
    0

    @Barney

    How i did this was to add a class to the list item (you could also do the link or whatever) of the file extension

    <xsl:attribute name="class">
    <xsl:value-of select="umbraco.library:GetMedia(current(), 'false')/data [@alias='umbracoExtension']" />
    </xsl:attribute>

    using the 2nd method (media picker to pick folder)

    <xsl:attribute name="class">
    <xsl:value-of select="current()/data [@alias='umbracoExtension']" />
    </xsl:attribute>

    Then all you have to do is add rules in the css to match up your favourite icon with the right class.  You can also do this with attribute selectors in css but they're not universally supported, so the above method is safer.

    Dan

  • BarneyHall 141 posts 210 karma points
    Nov 26, 2009 @ 15:00
    BarneyHall
    0

    Thanks Dan, you're a star. I'll give this a go... very much appreciated.

  • bob baty-barr 1180 posts 1294 karma points MVP
    Nov 30, 2009 @ 22:30
    bob baty-barr
    0

    any thoughts on a download counter? had a client ask me about it today and really had no idea where to start?

  • Frederik Vig 29 posts 61 karma points
    Nov 30, 2009 @ 23:58
    Frederik Vig
    0

    Hi Bob,

    I was in the same position a little over a month ago, and ended up creating some custom code for this.

    Here is the originale post with my solution in the second last post

    Hope it helps.

    Frederik

  • John 115 posts 150 karma points
    Aug 05, 2010 @ 03:45
    John
    0

    Hello there,

    I am a noobie and I'm not sure if it is correct ettiquette to come in on the end of the thread. I am having difficulties with Dandrayne's excellent looking XSLT and was wondering if anyone could give me a tip. I'm guessing it has something to do with 4.5 doing XSLT a bit different maybe.

    My full XSLT file looks like below (it's a copy of Dandrayne's with the different alias);

    <?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: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 ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">

    <xsl:variable name="mediaFolder" select="umbraco.library:GetMedia($currentPage/data [@alias='mediaDirectory'], 'true')" />
    <xsl:for-each select="$mediaFolder/node">
    <li>
    <a href="{current()/data [@alias='umbracoFile']}">
    <xsl:value-of select="current()/@nodeName" />
    </a>
    </li>
    </xsl:for-each>

    </xsl:template>
    </xsl:stylesheet>


    But it gives me the following error;

     
    

    Error occured

    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)


    If anyone had any thoughts on what might be causing that, I'd be very appreciative.

    Thank you

  • Steve Barnhouse 40 posts 63 karma points
    Aug 06, 2010 @ 02:31
    Steve Barnhouse
    1

    Nacho,

    I'm new here too, so this may not be all correct, but I've encountered similar problems, and this is what I've discovered:

    The 4.5 and 4.5.1 versions changed the xml and require different xslt.  

    Try changing from this: /data [@alias='umbracoFile']

    to this: /umbracoFile 

    Also, since you are using umbraco.library:GetMedia the document for which this xslt is executing has to have a property defined that has the type Media Picker.  If there is not a Media Picker property defined for your document then you will see that xslt error.

    --steve

  • John 115 posts 150 karma points
    Aug 06, 2010 @ 05:15
    John
    0

    Thanks Steve.

    A lot to learn isn't there :)

    I have ended up with the following which is working in 4.5.1. It works off a media picker that selects a folder. I still have to make it look pretty but it will display all the files in that folder.

        <xsl:if test="string($currentPage/mediaDirectory) != ''"> 
    <xsl:variable name="mediaFolder1" select="umbraco.library:GetMedia($currentPage/mediaDirectory, 1) /*" />
    <ul>
    <xsl:for-each select="$mediaFolder1/ancestor-or-self::* /*">
    <xsl:if test="string(current()/@nodeName) != ''">
    <li>
    <a href="{current()/umbracoFile}">
    <xsl:value-of select="current()/@nodeName" />
    </a>
    <p style="font-size:9px"><xsl:value-of select="current()/umbracoFile" /></p>
    </li>
    </xsl:if>
    </xsl:for-each>
    </ul>
    </xsl:if>


    Hopefully this will help the next noobie to come a long too.

  • Fabio Blardone 79 posts 98 karma points
    Mar 11, 2011 @ 11:48
    Fabio Blardone
    0

    Hello Dan,

    I'm using umbraco 4.5.2 on w.server 2003 r2 with .net 3.5,

    i'm trying your solution but when i save the xslt file return me an error : Error occured

    System.OverflowException: Valore troppo grande o troppo piccolo per un Int32.
    in System.Convert.ToInt32(Double value)
    in System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
    in System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    in System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    in System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    in (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    in Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    in Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    in System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    in System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
    in System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
    in System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results)
    in System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    in umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

    the mediapicker alias in the document type is right :(

    cheers,

    Fabio

Please Sign in or register to post replies

Write your reply to:

Draft