ICSharpCode.SharpZipLib.Zip.ZipFile.Delete C# (CSharp) Method

Delete() public method

Delete an entry by name
public Delete ( string fileName ) : bool
fileName string The filename to delete
return bool
        public bool Delete(string fileName) {
            if (fileName==null) {
                throw new ArgumentNullException("fileName");
            }

            CheckUpdating();

            bool result=false;
            int index=FindExistingUpdate(fileName);
            if ((index>=0)&&(updates_[index]!=null)) {
                result=true;
                contentsEdited_=true;
                updates_[index]=null;
                updateCount_-=1;
            } else {
                throw new ZipException("Cannot find entry to delete");
            }
            return result;
        }

Same methods

ZipFile::Delete ( ZipEntry entry ) : void

Usage Example

Example #1
2
        void TryDeleting(byte[] master, int totalEntries, int additions, params int[] toDelete)
        {
            MemoryStream ms = new MemoryStream();
            ms.Write(master, 0, master.Length);

            using (ZipFile f = new ZipFile(ms)) {
                f.IsStreamOwner = false;
                Assert.AreEqual(totalEntries, f.Count);
                Assert.IsTrue(f.TestArchive(true));
                f.BeginUpdate(new MemoryArchiveStorage());

                for (int i = 0; i < additions; ++i) {
                    f.Add(new StringMemoryDataSource("Another great file"),
                        string.Format("Add{0}.dat", i + 1));
                }

                foreach (int i in toDelete) {
                    f.Delete(f[i]);
                }
                f.CommitUpdate();

                /* write stream to file to assist debugging.
                                byte[] data = ms.ToArray();
                                using ( FileStream fs = File.Open(@"c:\aha.zip", FileMode.Create, FileAccess.ReadWrite, FileShare.Read) ) {
                                    fs.Write(data, 0, data.Length);
                                }
                */
                int newTotal = totalEntries + additions - toDelete.Length;
                Assert.AreEqual(newTotal, f.Count,
                    string.Format("Expected {0} entries after update found {1}", newTotal, f.Count));
                Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
            }
        }
All Usage Examples Of ICSharpCode.SharpZipLib.Zip.ZipFile::Delete