Using a Zip file as a SmartConnect Source
By default, we can’t use a zip file within SmartConnect as a data source directly, however we can write a pre-map script to extract the contents of the zip file.
This article is for the on-premise version of SmartConnect only and has only been verified with SmartConnect 20.18 and newer.
To begin, we need to add some .NET script namespaces to SmartConnect that will be used within our script. Unfortunately, the standard Script Namespace User window can’t be used for the System.IO.Compression assemblies that we need, so we’ll insert them directly into the proper SQL table.
These will insert into the ScriptNamespace table in the SmartConnect database. Be sure to change to the proper database name if not using the default name.
INSERT INTO SmartConnect..ScriptNamespace
SELECT ‘System.IO.Compression’, ‘System.IO.Compression’, 0
INSERT INTO SmartConnect..ScriptNameSpace
SELECT ‘System.IO.Compression.FileSystem’, ‘System.IO.Compression.FileSystem’, 0
After inserting these into our SQL table, be sure to restart SmartConnect.
Create a pre-map script to get the zip file and copy the contents, most likely to another folder that would be your data source folder.
If the filename is known, it can be hard coded as below and extracted to a folder.
If the zip file is going to be different each time, then it would require looping through the directory to find the file and extract it. This would also work if there are multiple zip files in the same directory when the map is run.
Dim extractPath as string = “C:\eOne\ZipFile\Source”
Dim files() as string = DirectoryInfo.GetFiles(“C:\eOne\ZipFile\Downloads”,”*.zip”)
For Each file as string in files
string extractPath = @”C:\eOne\ZipFile\Source”;
string files = DirectoryInfo.GetFiles(@”C:\eOne\ZipFile\Downloads”, “*.zip”);
foreach (string file in files)
Set up the map using the Folder Data source using the Source Folder that is referenced in your pre-map script. All the extracted files will then exist in this folder and those that match the template format will be properly processed.