Retrieving files within a script
Overview
CopyFile is a function provided by the script engine to download predefined sample files from the Appliance. In some scenarios, you may want to use the Appliance as a shared location that can store files required within Login Enterprise Application Scripts. This article explains how you can solve this requirement.
Script content
Within the Virtual Appliance file system, there is a directory called /scriptcontent/. The directory stores the template files used by the Knowledge Worker. Login Enterprise Administrators can include additional files here to be accessible as part of a Login Enterprise Application Script. For example, the Knowledge Worker's Word Script uses a template .DOCX and the Outlook Script uses template .PRF and .PST files that are shown below.
Log in as the local admin account and copy files into the /scriptcontent/ directory using the SSH file-transfer solution of your choice (We recommend WinSCP as it offers a GUI to simplify CLI operations). Suppose we added the file called Modeling_Template.xlsx, a sample Excel Spreadsheet containing financial data to model within an Application Script.
Retrieving files within a script
You can retrieve the file within an Application Script using the following syntax:
The CopyFile method accepts two parameters: sourcePath and destinationPath.
-
sourcePath: the location of a file that should be copied
- UrnBaseForFiles.UrnBase is a keyword that automatically maps to your /scriptcontent/ folder
- destinationPath: the location that the file should be copied to; a full destination path and file name
Copying files from the Appliance requires using an additional C# namespace. You can do this by adding the following command line to the top of your script:
Enhancements
Beloe are more detailed examples to illustrate practical usage scenarios and enhancements.
Consider using environment or standard variables to improve the readability. Here, the Temp environment variable is used.
The built-in Knowledge Worker Excel Script also provides a good example of how you can enhance the above example with dynamic environment variables, error handling logic, and logging:
In this example, the script:
1. Checks whether the template loginvsi.xlsx already exists locally within the Target
2. If not, it copies loginvsi.xls from /scriptcontent/loginvsi.xlsx to %TEMP%\LoginPI\loginvsi.xlsx
3. If it does exist, it creates a log noting it already existed
Alternatives
You can achieve the same outcome using a file server to store files. In scenarios where this is not feasible, delivery via the /scriptcontent/ is a viable solution.