Copied to clipboard

Flag this post as spam?

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


  • owen 8 posts 21 karma points
    Sep 29, 2009 @ 06:31
    owen
    0

    Use of folder location from folder picker

    Hi, i am looking to use the folder pick to allow a client to select a subfolder within the website structure. i have followed you brief install instructions and am able to get the folder picker to show in a content page after adding it to the datatypes and a document type.  What i am trying to work out is how i can use the folder path to pass to a macro that could be part of that content page and template, that will list all of the contents of that folder (subfile, ie images, documents, subfolders etc). could you suggest any way to use this path now i can select it. and if you know how to write a macro that will list contents of a folder would be helpfull too.  the content of the folder have not ben added to umbraco, they will be FTP'd up to the folder.  Thanksyou for you help.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Oct 13, 2009 @ 09:19
    Thomas Höhler
    0

    Hi Owen,

    missed your post completely. Have a lot of meetings today, but will answer this evening.

    Thomas

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Dec 02, 2009 @ 11:05
    Thomas Höhler
    0

    Hi Owen,

    sorry for the long long delay, I forgot you completely...

    You get as output the virtual path of the selected folder. e.g. if you have selected the folder images under your root folder you get as output "/images". Therefore that it is stored as the value of the generic property in the node you can use this in an xslt via

    <xsl:value-of select="$currentPage/data [@alias='ALIAS_OF_YOUR_PROPERTY']" />

    To list all files under a certain node you have to do some .net coding because there is no build in method to list all files of a folder, but this can easy be done with an xslt extension like this (not tested):

    public static XPathNodeIterator GetFilesFromFolder(string virtualFolder)
    {
    var server = System.Web.HttpContext.Current.Server;
    var folder = server.MapPath(virtualFolder);
    var doc = new XDocument();
    var root = new XElement("Files");
    doc.Add(root);
    XPathNavigator nav = doc.CreateNavigator();

    if (string.IsNullOrEmpty(folder))
    return nav.Select("/Files");

    foreach (var filePath in Directory.GetFiles(folder))
    {
    var entry = new XElement("File");
    root.Add(entry);

    entry.Add(new XElement("FileName", new XText(Path.GetFileName(filePath))));
    entry.Add(new XElement("Extension", new XText(Path.GetExtension(filePath))));
    entry.Add(new XElement("FilePath", new XText(filePath)));
    entry.Add(new XElement("VirtualFilePath", new XText(server.MapPath(filePath))));
    }

    return nav.Select("/Files");
    }

    So you can use this (after installing this extension) via

    <xsl:for-each select="YOUR_EXTENSION_ALIAS:GetFilesFromFolder($currentPage/data [@alias='ALIAS_OF_YOUR_PROPERTY'])/Files/File">
    <xsl:value-of select="FileName" />
    <xsl:value-of select="Extension" />
    <xsl:value-of select="FilePath" />
    <xsl:value-of select="VirtualFilePath" />
    </xsl:for-each>

    hth, Thomas

  • Aung Ko Lin 9 posts 78 karma points
    Dec 23, 2015 @ 10:35
    Aung Ko Lin
    0

    HI Thomas Hohler,

    I have already followed your installation: Installation: Just upload the dll to the bin folder, add a new datatype in the developer/datatypes section and choose TH.FolderPicker as RenderControl. Now you can select the base path from which the datatype will pick the folders. In the content section then the tree will be shown from the base path.

    But I can't see TH.Folder Picker in developer/datatypes. How do?

    thanks and best regards akl

Please Sign in or register to post replies

Write your reply to:

Draft