Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

Add file to Exists Zip file in windows phone

$
0
0

Hello,
i have a project Windows phone 8 and i must add a file into a exists zip file (created with sharpziplib).
I'm write this code but not it works

public void CreateZip()
{

        using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (isf.FileExists("CompressedFiles.zip")) isf.DeleteFile("CompressedFiles.zip");

            using (IsolatedStorageFileStream fsOut = new IsolatedStorageFileStream("CompressedFiles.zip", System.IO.FileMode.Create, isf))
            {
                 ZipOutputStream _zipStream;
                _zipStream = new ZipOutputStream(fsOut);
                _zipStream.SetLevel(7); 
                _zipStream.Close();
            }
        }

    }

private void AddFileToExistsZip(string path)
{

    using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
    {

        using (IsolatedStorageFileStream fsOut = new IsolatedStorageFileStream("CompressedFiles.zip", System.IO.FileMode.Append, isf))
        {
            ZipOutputStream zipStream = new ZipOutputStream(fsOut);

            string entryName;
            entryName = ZipEntry.CleanName(path); 
            ZipEntry newEntry = new ZipEntry(entryName);
            newEntry.DateTime = DateTime.Now;

            using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, System.IO.FileMode.Open, isf))
            {
                newEntry.Size = stream.Length;
            }

            zipStream.PutNextEntry(newEntry);

            byte[ buffer = new byte[4096];
            using (IsolatedStorageFileStream streamReader = isf.OpenFile(path, System.IO.FileMode.Open))
            {
                StreamUtils.Copy(streamReader, zipStream, buffer);
            }
            zipStream.CloseEntry();
            zipStream.Finish();
            zipStream.Close();
        }
    }

}

if i add a zip file have ONLY last file added Why?


Viewing all articles
Browse latest Browse all 1764

Trending Articles