I am wondering if anyone has come up with a way to forego the ZIP container around the CSV or XML files in favor of providing and export in CSV or XML without it being contained in a ZIP file. I would love to not have to uncompress the XML files and access them directly.
Ideally, I would like to be able to modify the OrderExport functionality to perhaps write a duplicate XML file into a separate directory with a static filename that is overwritten each time that an order export is executed so I would have a constant URL with updated data at each time an export is made.
Data Exchange Modifications (Alternative to ZIP Files)
-
- Ensign (ENS)
- Posts: 4
- Joined: Thu May 23, 2013 2:25 pm
Re: Data Exchange Modifications (Alternative to ZIP Files)
You can write a generic ASHX handler for a static URL. That generic ashx handler can scan a directory ( data exchange download folder) and detect the latest exported order file (compressed), un-compress it into memory or to a temporary location and return the contents to you.
Thanks for your support
Naveed Ashraf
.com
AbleCommerce Help Center
AbleCommerce Developer WIKI
Follow us on Twitter
Naveed Ashraf

AbleCommerce Help Center
AbleCommerce Developer WIKI
Follow us on Twitter
-
- Ensign (ENS)
- Posts: 4
- Joined: Thu May 23, 2013 2:25 pm
Re: Data Exchange Modifications (Alternative to ZIP Files)
That sounds awesome, but here's the catch. I am not familiar with ASHX, but I understand your logic here. Do you know of any particular examples of code that I can look at for this? I am used to PHP development and I am not a complete dummy when it comes to code, but knowing where to start would be awesome. Any ideas?
Re: Data Exchange Modifications (Alternative to ZIP Files)
I try to explain some related code stuff:
1. You can locate the latest modified file using some code below:
Add following namespaces with using statements:
Here is how you can uncompress the contents of zip file:
Add using statement at the top:
Uncompress to a directory:
I hope it will help.
1. You can locate the latest modified file using some code below:
Add following namespaces with using statements:
Code: Select all
using System.Collections.Generic;
using System.IO;
using CommerceBuilder.Common;
Code: Select all
string mappedPath = Server.MapPath("~/App_Data/DataExchange/Download/");
if (Directory.Exists(mappedPath))
{
string fileTypes = "ORDERS_*.zip";
string[] backupFilePaths = fileTypes.Split('|').SelectMany(filter => Directory.GetFiles(mappedPath, filter, SearchOption.TopDirectoryOnly)).ToArray();
if (backupFilePaths != null && backupFilePaths.Length > 0)
{
IList<FileInfo> backupFiles = new List<FileInfo>();
// GET FILE NAMES
for (int i = 0; i < backupFilePaths.Length; i++)
{
FileInfo fileInfo = new FileInfo(backupFilePaths[i]);
backupFiles.Add(fileInfo);
}
backupFiles.Sort("LastWriteTime", CommerceBuilder.Common.SortDirection.DESC);
// LAST MODIFIED FILE
FileInfo lastFile = backupFiles[0];
}
}
Add using statement at the top:
Code: Select all
using ICSharpCode.SharpZipLib.Zip;
Code: Select all
// UNCOMPRESS LAST FILE
// EXTRACT TO A TEMPORARY DIRECTORY, WHICH WILL BE DELETED AT THE END
string extractDirectory = "~/App_Data/DataExchange/Download/" + Guid.NewGuid().ToString() + "/";
try
{
FastZip fastZip = new FastZip();
fastZip.ExtractZip(filePath, SafeMapPath(extractDirectory), string.Empty);
// LOCATE THE UNCOMPRESSED FILE, AND PROCESS THE FILE CONTENTS
}
finally
{
// DELETE THE TEMP DIRECTORY
Directory.Delete(SafeMapPath(extractDirectory), true);
}
Thanks for your support
Naveed Ashraf
.com
AbleCommerce Help Center
AbleCommerce Developer WIKI
Follow us on Twitter
Naveed Ashraf

AbleCommerce Help Center
AbleCommerce Developer WIKI
Follow us on Twitter
-
- Ensign (ENS)
- Posts: 4
- Joined: Thu May 23, 2013 2:25 pm
Re: Data Exchange Modifications (Alternative to ZIP Files)
Thank you Naveed. This will help greatly. I will begin trying to implement some of this and give it a shot.