Let's build the future of DNN as partners. Become an investor for as low as $150 Invest Now
16 Jul 2019

#64: How to Build a File Manager

This is a video tutorial showing a simple implementation of a File Manager built entirely with DNN Sharp Modules.

When we talk about file management in DNN, the default File Manager has a lot of options but when it comes to configuring it you will notice that you are kinda restricted and you have no options to add your own custom business logic.

We will show you in the video how to overcome this limitation with the help of just 3 of the powerful and flexible DNN modules offered by DNN Sharp: Action Form, Action Grid and MyTokens. You can have the same power offered by the DNN File Manager but also extend it as you want to by using all the cool features of the best DNN modules.

This is just a simple example but it can be extended. Think about this setup is just a starting point for something more complex, where you can add the features both you and your clients need. You are creating your own custom File Management solution by using 3 easy to configure DNN modules.

Where does each module come to help? It's easy:

  • Action Grid is used to display data from the database (it is the files "viewer")
  • Action Form is used to browse folders and to upload new files
  • MyTokens is used to generate HTML with downloadable links for the files based on their ID from the database

The video is based on a key feature from Action Grid called Sync with Url which was detailed in another video tutorial that showed how you can refresh and filter your grids without refreshing the page and can be seen here.

Have a look at the video and make sure you put it in practice for your future custom projects. If you have more complex scenarios to be implemented you can simply book our Implementations Team to build the project for you.

Below you will find the needed SQL Query and the export of the MyTokens custom token as we've built it for this video.

SQL Query

select

   iif(FolderPath = '',

       '<root>',

       SUBSTRING(

           left('/' + FolderPath, len('/' + FolderPath) - 1),

           LEN(left('/' + FolderPath, len('/' + FolderPath) - 1)) - CHARINDEX('/', REVERSE(left('/' + FolderPath, len('/' + FolderPath) - 1))) + 2,

           LEN(left('/' + FolderPath, len('/' + FolderPath) - 1))

       )

   ) as Text,

   FolderID as Value,

   FolderID as ItemId,

   ParentID as ParentId,

   iif(FolderPath = '', '', '/' + LEFT(FolderPath, LEN(FolderPath) - 1)) as Path,

   1 as IsSelectable,

   IIF((Select count(*) from Folders F where F.ParentId = Fol.FolderId) > 0, 'true', 'false') as HasChildren

from Folders Fol

where PortalID = 0 and

   (

       (ParentID = @parentId and @parentId != -1)

       or

       (ParentID = 36 and @parentId  = -1)

       or

       (@searchText != '' and (FolderID = @searchText or FolderPath like '%' + @searchText + '%'))

   )

Exported MyTokens custom token

<namespaces>

  <ns>

    <name>FileManager</name>

    <desc />

    <allPortals>true</allPortals>

    <tokens>

      <tkn>

        <name>DownloadLink</name>

        <desc />

   <src>&lt;src&gt;&lt;type&gt;razor&lt;/type&gt;&lt;lang&gt;csharp&lt;/lang&gt;&lt;script&gt;@DotNetNuke.Services.FileSystem.FileLinkClickController.Instance.GetFileLinkClick(DnnSharp.Common.IO.StorageUtils.GetFile(TknParams.Identifier.Value.ToString(), DotNetNuke.Entities.Portals.PortalController.Instance.GetCurrentPortalSettings()))&lt;/script&gt;&lt;assemblies&gt;~/bin/DnnSharp.Common.dll&lt;/assemblies&gt;&lt;compiledRazorLocation&gt;host&lt;/compiledRazorLocation&gt;&lt;debugScript&gt;false&lt;/debugScript&gt;&lt;/src&gt;</src>

        <parser />

        <default />

        <cacheTime>3600</cacheTime>

        <cacheLayer>Global</cacheLayer>

        <server />

      </tkn>

    </tokens>

  </ns>

</namespaces>


Latest Posts from 1001

29 Aug 2019

#66: Manipulate Cookies with MyTokens

9 Aug 2019

#65: Google Maps Location Picker with markers and radius

16 Jul 2019

#64: How to Build a File Manager