vb.net zip overwrite files in zipped directory -


i got code zip files in directory. here is

private sub zipfiles()          dim zippath string = "c:\temp\compression\myzip.zip"          'open zip file if exists, else create new 1           dim zip package = zippackage.open(zippath, _                io.filemode.openorcreate, io.fileaccess.readwrite)          'add many files like:         addtoarchive(zip, "c:\temp\compression\compress me1.txt")          addtoarchive(zip, "c:\temp\compression\compress me2.txt")          addtoarchive(zip, "c:\temp\compression\compress me3.txt")          zip.close() 'close zip file      end sub       private sub addtoarchive(byval zip package, _                           byval filetoadd string)          'replace spaces underscore (_)          dim urifilename string = filetoadd.replace(" ", "_")          'a uri starts forward slash "/"          dim zipuri string = string.concat("/", _                     io.path.getfilename(urifilename))           dim parturi new uri(zipuri, urikind.relative)          dim contenttype string = _                    net.mime.mediatypenames.application.zip          'the packagepart contains information:          ' extract file when it's extracted (parturi)          ' type of content stream (mime type):  (contenttype)          ' type of compression:  (compressionoption.normal)            dim pkgpart packagepart = zip.createpart(parturi, _                    contenttype, compressionoption.normal)          'read of bytes file add zip file          dim bites byte() = file.readallbytes(filetoadd)          'compress , write bytes zip file          pkgpart.getstream().write(bites, 0, bites.length)      end sub 

but code creating problem when file present in zipped folder. gives exception. how can overwrite files present ?

also, code little slow, there fast way zip files ?

try this

'open zip file if exists, else create new 1      dim zip package = zippackage.open(zippath, _                    io.filemode.create, io.fileaccess.readwrite, io.fileshare.read) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -