Move ZipEntry of ZipFile to perticular location ? RRS feed

  • Question

  • Hi,

    I want to know that how to move a zipentry to different location.

    If i take a example..

    foreach (ZipEntry e in zip)
                                if (e.IsDirectory == false && (e.FileName.Contains("CalData") == false) && (e.FileName.Contains("_") == true))
                                    string[] fileFetch = e.FileName.Split('/');
                                    string fileFetchEx = fileFetch[0] + "\\" + fileFetch[2];
                                    if ((fileFetch[2].Contains("CalData") == false) && (fileFetch[2].Contains("_") == true))
                                        System.Data.Linq.ISingleResult<ShopBatchTransactionDetail> sp = db.ShopBatchTransactionDetailReadByFile(stagingLocation + fileFetchEx);
                                        int count = (from t in db.ShopBatchTransactionDetailReadByFile(stagingLocation + fileFetchEx)
                                                     select t).Count();
                                        if (count > 0)
                                            db.ShopBatchTransactionDetailUpdate(shopBatchTransactionDetailId, skippedStatus, user);
                                            //foreach (ShopBatchTransactionDetail entry in sp)
                                            //if (entry.FilePath != (stagingLocation + fileFetchEx))
                                                string shopFolder = fileFetch[0].Substring(0, 3);
                                                string finalPath = shopFolder + "/" + fileFetch[2];
                                                e.FileName = finalPath;
                                                e.Extract(stagingLocation, ExtractExistingFileAction.OverwriteSilently);
                                                e.FileName = fileFetch[0] + "/" + fileFetch[1] + "/" + fileFetch[2];

    As shown on my above code, I removed one folder from ZipEntry e,

    as it was e.FileName = "Folder1/Folder2/File1.txt" and i modified it to

    e.FileName = "Folder1/File1.txt", that is what i needed.

    But then in my code i got below error.

    "Collection was modified; enumeration operation may not execute."

    Please help me in this.

    Saturday, April 27, 2013 11:45 AM


  • Hi Dynamic,

    Welcome to the MSDN Forum.

    This is by design. You cannot modified the collection foreach statement is enumerating.

    When you need to change the element during the enumeration, please use for or while, both them have no such limitation.

    I hope this will be helpful.

    Best regards,

    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 29, 2013 6:53 AM