Subject: Error while Updateing a Zip with transaction
Date: 2012-04-10 11:03:29
From: Joerg Schlenker
Source: error-updateing-zip-transaction
----------------------------------------------------------------------

hello,

i use the following method:

public static void zip(string targetFileName, Dictionary<string, string> dictFilesToZip, string action)
{

            #region zip
            Zip zip = new Zip();
            if (action.Equals("append"))
            {
                zip.Open(targetFileName, FileMode.Open);
            }
            else
            {
                zip.Create(targetFileName);
            }

            //TransferOptions opt = new TransferOptions();
            //opt.FileExistsResolveAction = FileExistsResolveAction.OverwriteAll;


            zip.BeginUpdate();
            try
            {
                foreach (KeyValuePair<String, String> entry in dictFilesToZip)
                {
                    //string path_to_file = Path.GetDirectoryName(entry.Key);
                    //string filename = Path.GetFileName(entry.Key);
                    //string[] file = new string[1];
                    //file[0] = filename;
                    //zip.AddFile()
                    //zip.AddFiles(path_to_file, file, Path.GetDirectoryName(entry.Value).Replace(Path.DirectorySeparatorChar.ToString(), "/"), opt);

                    string strTargetFile = entry.Value.Replace(Path.DirectorySeparatorChar.ToString(), "/");
                    if (zip.FileExists(strTargetFile))
                        zip.DeleteFile(strTargetFile);

                    zip.AddFile(entry.Key, strTargetFile);
                }
            }
            catch (Exception ex)
            {
                zip.CancelUpdate();
                throw ex;
            }
            finally
            {
                zip.EndUpdate();
                zip.Close();
            }
            #endregion
        }

Calling:

string targetFileName = @"e:\DEV\DotNet\zipper\TestFiles\e0745045-54cf-45bb-a714-2d72c906a865_FRA_00_J00002314.ppf";
                Dictionary<string, string> dictFilesToZip = new Dictionary<string, string>();
                dictFilesToZip.Add(@"e:\DEV\DotNet\zipper\TestFiles\FuzzyTest_doc.doc", @"ORG\orig_FuzzyTest_doc.doc");
                dictFilesToZip.Add(@"e:\DEV\DotNet\zipper\TestFiles\FuzzyTest_doc2.doc", @"ORG\orig_FuzzyTest_doc2.doc");

                string action = "append"; // TODO: Initialize to an appropriate value

                ZipHelper.zip(targetFileName, dictFilesToZip, action);

My Problem is at the zip.EndUpdate();. I get the error that a closed zip could not be closed.

Before I used the commeted Code, with this it works fine. It also works if i remove the begin, end update thing?!?

Thanks for your help

---------------------------------------------------------------------- Note: This question has been asked on the Q&A forum of Thang Dang's fraudulent ComponentPro brand If you purchased anything from ComponentPro, you have been scammed. Contact the payment processor who sold you the license and ask for your money back. Back to ComponentPro Q&A Forum Index