or
Hello
I'm trying to create a ZIP file from Silverlight with a list of JSON data and compresses well. The problem is to receive it in the server because I have no library Telerik receive the Zip to extract and process the result. The library I am using is IonicZip to receive the result but I get error trying to read the MemoryStream. Is there a library for ASP.net Telerik decompress the ZIP file
Code in Silverlight:Code in WCF:MemoryStream memoryStream =
new
MemoryStream();
ZipCompression method = ZipCompression.Default;
Telerik.Windows.Zip.ZipOutputStream zipOutputStream =
new
Telerik.Windows.Zip.ZipOutputStream(memoryStream, method);
StreamWriter writer =
new
StreamWriter(zipOutputStream);
writer.Write(listSave.ToJSON());
writer.Flush();
ServicesClient context =
new
ServicesClient();
context.SetZipFileAsync( Convert.ToBase64String(memoryStream.ToArray()));
public
void
SetZipFile(
string
_parameter)
{
if
(!
string
.IsNullOrWhiteSpace(_parameter))
{
var info = Convert.FromBase64String(_parameter);
MemoryStream stream =
new
MemoryStream(info);
string
dataList =
string
.Empty;
MemoryStream output =
new
MemoryStream();
StreamReader read =
new
StreamReader(output);
using
(ZipFile zip = ZipFile.Read(stream))
{
ZipEntry item = zip[0];
item.Extract(output);
output.Seek(0, SeekOrigin.Begin);
dataList = read.ReadToEnd();
}
}
}
string wavFilePath = @"C:\1\cheer.wav";
string wavFileNewPath = @"C:\1\cheerNew.wav";
string zipFilePath = @"c:\1\123.zip";
private void btnCompress(object sender, RoutedEventArgs e)
{
FileStream fs = new FileStream(wavFilePath, FileMode.Open);
SizeBefore.Text = fs.Length.ToString();
using (ZipPackage zipFile = ZipPackage.CreateFile(zipFilePath))
{
zipFile.AddStream(fs, "cheer.wav", ZipCompression.Default, DateTime.Now);
zipFile.Close(true);
}
}
private void btnUncompress(object sender, RoutedEventArgs e)
{
using (ZipPackage zipFile = ZipPackage.OpenFile(zipFilePath, FileAccess.Read))
{
ZipPackageEntry zipEntry = zipFile.ZipPackageEntries[0];
Stream strm = zipEntry.OpenInputStream();
byte[] Bytes = new byte[strm.Length];
strm.Read(Bytes, 0, (int)strm.Length);
using (FileStream fs = new FileStream(wavFileNewPath, FileMode.Create))
{
fs.Write(Bytes, 0, Bytes.Length);
fs.Close();
}
}
}
Dim inputStream As New ZipInputStream(memStream)
Hi there,
I've got a small application and now stuck in the task "Appending Files in Zip".
As far as it looks the ZipPackage only allow to Read or Write. Not both.
The Codeblock with the routine
ZipPackage zipPackage;
if
(File.Exists(appPath + @
"\"
+ currentMonthZip))
{
Stream stream = File.OpenRead(appPath + @
"\"
+ currentMonthZip);
zipPackage = ZipPackage.Open(stream, FileAccess.ReadWrite);
}
else
{
Stream stream = File.Create(appPath + @
"\"
+ currentMonthZip);
zipPackage = ZipPackage.Create(stream);
}
foreach
(
string
folderName
in
logFoldernames)
{
string
[] listLogs = Directory.GetFiles(appPath + @
"\"
+ folderName);
foreach
(
string
listLogName
in
listLogs)
{
zipPackage.Add(listLogName, folderName + @
"\"
+ Path.GetFileName(listLogName));
}
Directory.Delete(appPath + @
"\"
+ folderName);
}
I'm aware that maybe the problem lays here but change the FileAccess or FileMOde ends in exceptions (Stream not for Read/Write)
Stream stream = File.OpenRead(appPath + @
"\"
+ currentMonthZip);
zipPackage = ZipPackage.Open(stream, FileAccess.ReadWrite);
So what's the suggested approach to open an existing Zip and just attach some new Files in it?
Do I really have to create a temporary zip with old and new content and afterwards delete the old zip and rename the new to the proper name?
Thanks for any help.