Copied to clipboard

Flag this post as spam?

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


  • Patrik D 7 posts 47 karma points
    Apr 05, 2015 @ 13:31
    Patrik D
    0

    Struggling with GetMedia

    Hello!

    I'm fairly new to Umbraco and working on my first XSLT. I'm having trouble wrapping my head around why GetMedia won't work using my variable, so would like some pointers on what it may be. I've looked at the examples in the reference library, but doesn't seem to get the input right from my variable.

    Think this code is enough:

    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
      <xsl:sort select="@sortOrder" order="descending" data-type="number" />
    
      <xsl:choose>
          <xsl:when test="position() = 1">
            <div class="latestIssue">
              <p>
                <xsl:variable name="mediaPDF" select="current()/attachPDF" />
                <a target="_blank">
                  <xsl:attribute name="href">
                    <xsl:value-of select="umbraco.library:GetMedia($mediaPDF, 0)/umbracoFile" />
                  </xsl:attribute></a>
              </p>
            </div>
          </xsl:when>
    

    When I try to save this code I get 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.Double.System.IConvertible.ToInt32(IFormatProvider provider) 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 Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver) 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 I print mediaPDF using value-of, I get the media ID for the PDF and if I hardcode this instead of $mediaPDF it works fine.

    The general setup is that I have a document type which has children, for which each child has a alias (attachPDF) where the media picker is used. So on the page where I use the parent, I like to loop through all children and create links to each PDF that is defined for the children.

    Hope you understand what I'm trying to achieve.

    Thanks in advance.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 05, 2015 @ 14:02
    Jan Skovgaard
    100

    Hi Patrik and welcome to our :)

    What version of Umbraco are you using?

    The reason why you're getting the error above is because one of the values you're trying to fetch might be emtpy, which means that the GetMedia() extension is getting an empty id value, which makes it throw up...And sometimes it will throw up because the value is not known until the code is being executed.

    So you should try using this instead

      <xsl:choose>
          <xsl:when test="position() = 1">
    <xsl:if test="current()/attachPDF">
            <div class="latestIssue">
              <p>
                <xsl:variable name="mediaPDF" select="current()/attachPDF" />
                <a target="_blank">
                  <xsl:attribute name="href">
                    <xsl:value-of select="umbraco.library:GetMedia($mediaPDF, 0)/umbracoFile" />
                  </xsl:attribute></a>
              </p>
            </div>
    </xsl:if>
          </xsl:when>
    

    It's not the best example but it should do the trick if I remember correctly though.

    Hope this helps.

    /Jan

  • Patrik D 7 posts 47 karma points
    Apr 05, 2015 @ 19:20
    Patrik D
    0

    Thank you! Started off a bit bumpy when I started using Umbraco, but starting to get a hang of it :)

    Thanks for the help, worked like a charm!

    The website runs Umbraco v4.7.0, it's been up for a while. I'm not the original developer nor in charge of the design work, so just trying to use what I got at my disposal :)

    Would it be much work to upgrade to the current version? There are some custom packages installed, so don't know how they would be affected if the platform is updated. While where at it, is it possible to take a .dll file in the bin-folder and "decompile" it? Would be neat to look at the code of our custum package to see what it does.

    Thanks again!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Apr 06, 2015 @ 01:11
    Jan Skovgaard
    0

    Hi Patrik

    Glad it helped :)

    Well, to be honest - Yes it will take a lot of work to upgrade this version to latest version of 7.2.x since A LOT has changed since this release.

    The underlying API's have changed with the release of Umbraco 6 and with the release of Umbraco 7 the backoffice has got a nice overhaul and is now based on angularjs, which mean that many 3rd party packages that are compatible with older versions of Umbraco might not work anymore. And since underlying API's has changed as well then any custom integration relying on these will probably need a rewrite as well.

    Furthermore MVC was introduced in Umbraco 4.10 and in v7 it's the default template engine even though it is possible to enable webforms instead.

    So this is just a quick mention of some of the major things that has happened since this version you're working on.

    So before considering an upgrade you need to think very much about what could go wrong and what you need to take into account - Perhaps it's better to just migrate the site into a fresh installation instead for instance - But even this approach is not necessarily easy in any way since there might be content based on a datatype/property editor, which may not exist on v7 or has been refactored so it's working differently. So it requires you to have a much better overview of your current solution.

    You can read about the upgrade process in the documentation area - Even though it covers many things it can never cover custom stuff so there are still things to be aware of even though you read through it all and think you got everything covered. https://our.umbraco.org/documentation/Installation/Upgrading/ - Make sure to read EVERYTHING in these links.

    Since you're on a very old installation you will probably find that some of those Umbraco versions you need to upgrade to are no longer available from official sources - But Lee Kelleher has got your back with an unoifficial stash of releases here http://code.leekelleher.com/umbraco/archive/

    Recently this blogpost has appeared about the process of upgrading from v4.x to 7.x http://www.blix.co/blog/2014/6/5/follow-the-path-upgrading-umbraco-from-v4-to-v7.aspx - But once again keep in mind that the author of this blogpost does not know the ins and outs of your particular Umbraco setup and installation so even though there is a lot of good information in there he might not cover all the things that you need to consider.

    In regards to figuring out what code the former developer has written you should be able to use something like Reflector to decompile the .dll files and see what the source code looks like.

    I hope this helps :)

    /Jan

  • Patrik D 7 posts 47 karma points
    Apr 06, 2015 @ 07:20
    Patrik D
    0

    Thanks a lot Jan, you helped alot :)

Please Sign in or register to post replies

Write your reply to:

Draft