I am unzipping a zipped csvfile and saving it to a path. It does save but when I open it later for processing, it is unreadable. I've included my code - may be a simple correction or addition to code here but I'm hung up! Also, am I setting the size incorrectly - not sure on this either. Fastest solution/fix to my code that works gets points. [I need this to save the unzipped file.csv such that when opened programmaticaly it is readable]
public static string UnZipFiles(string zipPathAndFile, string outputFolder, string password, bool deleteZipFile, int FileNum)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(zipPathAndFile));
string sReturnFileToProcess = "";
string TempUnZipFolder = "";
string sFileNamed = "";
TempUnZipFolder = @"\\\\server\\driveletter$\\folder\\anotherfolder\\";
if (password != null && password != String.Empty)
s.Password = password;
ZipEntry theEntry;
string tmpEntry = String.Empty;
while ((theEntry = s.GetNextEntry()) != null)
{
// string directoryName = outputFolder;
string directoryName = TempUnZipFolder;
string fileName = Path.GetFileName(theEntry.Name);
// create directory
if (directoryName != "")
{
Directory.CreateDirectory(directoryName);
}
if (fileName != String.Empty)
{
if (theEntry.Name.IndexOf(".ini") < 0)
{
string fullPath = TempUnZipFolder + "\\" + FileNum.ToString() + "_" + theEntry.Name;
sFileNamed = FileNum.ToString() + "_" + theEntry.Name;
sReturnFileToProcess = sFileNamed;
fullPath = fullPath.Replace("\\ ", "\\");
string fullDirPath = Path.GetDirectoryName(fullPath);
if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
FileStream streamWriter = File.Create(fullPath);
int size = 20480;
byte[] data = new byte[20480];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
}
s.Close();
if (deleteZipFile)
{
File.Delete(zipPathAndFile);
}
return sReturnFileToProcess;
}
Thank in advance!