I am able to create a zip file without a problem. The problem comes in when the files are extracted from the new zip file it contains folders for the entire directory path (e.g., C:\Test\Build\Local Cubes\New York) instead of what I expected (e.g., New York and the files in this folder). I'm using J# components to create the file, but this is my first crack at it and would like to know how to create a self-extracting zip that may correct this issue. Here is the code for creating the zip file.
private void m_BuildZip()
{
// Get list of files to zip.
FileStream objFile;
string strFile;
string DirPath = "\\\\servername\\c$\\Inetpub\\wwwroot\\UnitNames\\New York.xls";
string sDir = (DirPath);
string[] files = Directory.GetFiles(sDir, "*.xls");
//Create zip file containing all .xls files in directory.
CRC32 objCRC32=new CRC32();
objFile=File.Create(DirPath + "\\" + ddlGroup.SelectedItem.Text.ToString() + ".zip");
objFile.Close();
ZipOutputStream zipFile=new ZipOutputStream(new java.io.FileOutputStream
(objFile.Name.Substring(60).ToString()));
zipFile.setLevel(6);
foreach (string file in files)
{
FileStream fs=File.OpenRead(file);
byte [] buffer=new byte[fs.Length-1];
sbyte[] buffer1=new sbyte[fs.Length-1];
strFile=file.Substring(file.LastIndexOf("/")+1);
fs.Read(buffer,0,buffer.Length);
ZipEntry objZipEntry=new ZipEntry(strFile);
java.io.FileInputStream from=new java.io.FileInputStream(file);
zipFile.putNextEntry(objZipEntry);
CopyStream(from,zipFile);
objZipEntry.setMethod(ZipEntry.DEFLATED);
fs.Close();
zipFile.closeEntry();
}
zipFile.flush();
zipFile.close();
objFile.Close();
}
public static void CopyStream(java.io.InputStream from, java.io.OutputStream to)
{
sbyte[] buffer = new sbyte[8192];
int got;
while ((got = from.read(buffer, 0, buffer.Length)) > 0) to.write(buffer, 0, got);
}