In previous releases of Aras Innovator, it was possible to download multiple files to a client machine at one time. However, with the move away from .NET Controls in 11.0 SP9, access to the client's file system became limited. In today's blog post, we will be going over a technique that you can use in newer versions of Aras Innovator to allow your users to download multiple files at once.

Getting Started

The code shown below is part of the Download Multiple Files Aras Community Project. If you want to apply the project or view the source code in its entirety, you can find it on the Aras Labs GitHub:

ArasLabs/download-multiple-files

download-multiple-files – Contains sample methods for how to download multiple files from the main grid and the relationships grid.

How It Works

The way that we can download multiple files is can be outlined in the steps below.

  1. Get the IDs of the items selected and pass them to a server-side method
  2. Create a temporary directory on the Aras Innovator server
    1. In this sample, we use the ID of the user to avoid conflicts if multiple users run this method at once
  3. Download all of the files to this temporary directory on the server
  4. Programmatically add these files to a Zip archive
  5. Upload this Zip archive to the Vault
  6. From the client method, download this newly added File from the Vault
  7. Once the file has finished downloading, cleanup the files
    1. Delete the File Item from the Vault
    2. Delete the temporary directory from the Server

Applying the Technique

Selecting Multiple Related Items

The first step is to get a list of the selected File IDs. Processing selected items from the Main Grid has already been covered in a previous blog post, so we will instead cover how to handle multiple selected items from the Relationships Grid. By default, an action attached to a RelationshipType will execute once for each item selected. We don't want to download our files multiple times, so we need to limit the execution of this action to just one of the selected items. We can do this with the sample below.

gist.github.com/…/5a1f009ce2efe80384b0a6f98a671cda

In this sample, we're checking that the current item is the last item in our selection. This check will be performed on each selected item, but we can be sure that the rest of the method executes only once.

Creating the Zip File

The next step is to write our Server Side method for creating the Zip File. The sample below performs steps 2-5 described above.

gist.github.com/…/30d5ac2d0abb5e479610e523968a3ec0

If you try to compile this code as is, you'll receive an error indicating that the ZipFile namespace we're trying to use does not exist. In order to resolve this error, we'll need to add the System.IO.Compression.FileSystem.dll to the InnovatorServermethod-config.xml file as seen below.

Deleting the Zip File

Next we'll need to write our Server Side method to perform the cleanup of deleting the file from the Vault as well as deleting our temporary directory. The sample below performs step 7 described above.

gist.github.com/…/4968b4a6d31413979be5bcd59f00ca9a

Full Client Side Method

With our Server Side methods complete, we can put all of our code together into our final client-side action. In between the creation and deletion of the zip file, we will also include a call to download the file to the client.

gist.github.com/…/2f2f1a8d93b3f9d89f80d513e7f6ca61

You can see an example of the action being run below.

LOOKING FOR MORE ARAS INSPIRATION?

Subscribe to our blog and follow @ArasLabs on Twitter for more helpful content! You can also find our latest open-source projects and sample code on the Aras Labs GitHub page.