CreateDirectory Overview

CreateDirectory is used to create a directory on target file system. You should use this service if the directory does not exists. The service will create the directory on application server by default, unless you specify the target server name in the directory path.

This can be helpful when you need to dynamically create a directory based on the user or entity the files you wish to save are associated with. For example, saving images or message attachments that are stored in a directory that correspond to the particular message/userid it belongs to.

CreateDirectory Use Examples

Basic CreateDirectory Use

This is an example that we specify a path on application server and create the directory.

The log shows it runs successfully.

Then on the application server, you will see the directory created.

If the directory already exists, the service will return False.

Using CreateDirectory for Message Attachments

In this example, we examine a feature called the message center. Users with access (like an admin) have the ability to save messages and provide attachments. Then, certain users receive a notification that a new message exist and can be viewed. Upon viewing the message, the attachment is available to all users viewing the new message.

This is done by dynamically creating a directory based on the MessageId. Each time a message is created, it is first assigned a MessageId. Then, in order to add an attachment, the process puts together the file paths for the “Attachments” parent folder, the “MessageCenter” folder within that, and the “[MessageId]” folder within that (this one may not exist yet if the message is new). This is done in the “Paths” evaluate.

From there it checks if the directory for the MessageId exists. As mentioned, if the message is new, it won’t exist yet. This is where CreateDirectory is used. After finding the MessageId folder exists or creating it, the attachment is saved to that folder.

Here is the CreateDirectory configuration

Create Directory on other server

This an example that we create a directory on another server. Please note that you need to put the server name at the beginning. You can also use IP address instead of the server name.

The format is:

\\[Server Name or IP]\C$\dir1

From the file explorer, you can see the directory is created on target server.