Created
June 7, 2018 21:06
-
-
Save cgillis-aras/30d5ac2d0abb5e479610e523968a3ec0 to your computer and use it in GitHub Desktop.
Demonstrates how to download files in the Vault to the server and add them to a .Zip Archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Innovator inn = this.getInnovator(); | |
// Make sure some ids were passed in | |
if (String.IsNullOrEmpty(this.getProperty("file_ids"))) | |
{ | |
return inn.newError("No Files specified to download."); | |
} | |
// User the Users ID to create a temporary directory | |
string folderPath = @"C:\Temp\Aras\MultipleFileDownload\" + inn.getUserID(); | |
string filePath = folderPath + "\\Files"; | |
string zipPath = folderPath + "\\Zip"; | |
// Create folder for this action | |
if (System.IO.Directory.Exists(folderPath)) | |
{ | |
System.IO.Directory.Delete(folderPath, true); | |
} | |
System.IO.DirectoryInfo di = System.IO.Directory.CreateDirectory(filePath); | |
System.IO.DirectoryInfo zdi = System.IO.Directory.CreateDirectory(zipPath); | |
// Get a collection of the files we will want to download | |
Item files = inn.newItem("File", "get"); | |
files.setAttribute("idlist", this.getProperty("file_ids")); | |
files = files.apply(); | |
if (files.isError()) | |
{ | |
return files; | |
} | |
// Create a checkout manager to download all of the files to the server | |
Aras.IOME.CheckoutManager cm = new Aras.IOME.CheckoutManager(files); | |
cm.DownloadFiles(filePath, 1); | |
// Once the files are downloaded to the server, create a zip file | |
const string zipName = "AllFiles.zip"; | |
string fullZipPath = String.Format("{0}\\{1}", zipPath, zipName); | |
try | |
{ | |
if (System.IO.File.Exists(fullZipPath)) | |
{ | |
System.IO.File.Delete(fullZipPath); | |
} | |
System.IO.Compression.ZipFile.CreateFromDirectory(filePath, fullZipPath); | |
} | |
catch (InvalidDataException) | |
{ | |
return inn.newError("Could not create .zip archive"); | |
} | |
// Upload this .zip to Innovator | |
Item zipFile = inn.newItem("File", "add"); | |
zipFile.setProperty("filename", zipName); | |
zipFile.attachPhysicalFile(fullZipPath); | |
zipFile = zipFile.apply(); | |
return zipFile; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment