Tips & Tricks - Open FileWalker in a Specific Directory

This post shows how to modify FileWalker so that a specific directory is selected when a page loads.

Connection

In the "Integration" module, a FileWalker connection was configured for the path "c:\documents". Click here to learn how to create a connection.

The "c:\documents" directory contains subfolders for different types of documents. There is also a "customers" directory there, which in turn contains one folder for each customer number. Documents such as contracts, purchase orders, etc., are stored in these customer folders.

View in Browser

In the corresponding application, all customer numbers are listed in a table view. Clicking the magnifying glass button loads a view page that contains a FileWalker element with the previously created FileWalker connection selected in its properties. In our example, the FileWalker element should automatically navigate to the "contract" subdirectory associated with the selected customer number each time it loads.

In Example 1 below, you can navigate back to the root directory of the FileWalker connection and, consequently, to any customer directory. This grants access rights that may not be intended!

In Example 2, you cannot navigate back. The subdirectory is set as the new root directory.

The choice of example is primarily a security consideration regarding access to the managed files. In both examples, there is currently no check to see if the subdirectory exists.

Example 1: Navigating to a subdirectory

The caller includes the "subDir" parameter (request name: "qs_subDir"), which specifies the FileWalker's subdirectory. The value of the parameter can be dynamically constructed in the properties dialog for the table column that contains the button, for example, using Velocity:

            #set($customerid = $drRecord.getValue('<GUID table colums>').asString())
#set($path = "customers/" + $customerid + "/contract")
$path

        

In the script, insert the GUID of the table column that contains the customer number. The GUID can be found in the table column properties on the "Expert" tab. The view page then automatically evaluates the parameter when it loads and loads the corresponding subfolder.

Example 2: Setting a New Root Directory

The caller sends a parameter whose value is further processed in the RenderingHandler of the page where the FileWalker is located and is added to the session. You can choose any name for the parameter; in our example, it is "customerid." As with Option 1, the parameter in this example is again defined in the properties of a button in the view table that contains the customer numbers.

The RenderingHandler on the page containing the FileWalker element adds the key "FILEWALKER_DYNPATH_<GUIDFILEWALKERKONTROLLE>" to the session. The value of this variable is the subdirectory to be accessed. Since the subdirectory has been added to the session, this setting remains in effect for every call until the value is actively removed from the session.

            if (g_parameter.containsParameter("customerid")) 
{ 
	def customerid = g_parameter.get("customerid")
	def path = "customers/${customerid}/contract"
	g_session.put("FILEWALKER_DYNPATH_547ABBCCFC94390342DAD464106A1D5748E4A39E", path.toString()) 
} 
else 
{
	g_session.remove("FILEWALKER_DYNPATH_547ABBCCFC94390342DAD464106A1D5748E4A39E") 
}