في فيجوال بيسك 4 توجد هناك كلاسات تتعامل مع zip مباشرة
اولا : عليك بتحويل الTarget Framework لمشروعك الى 4.5
ثانيا : قم باضافة المراجع
System.IO.Compression و
System.IO.Compression.FileSystem
ثاثا : اضف في اعلى المحرر
Imports System.IO.Compression
رابعا : لو كان عندي ملف مضغوط باسم update.zip لو حبيت اعرف اسماء الملفات التي بداخله :-
PHP كود :
Const zipfile As String = "C:\Users\Fti\Desktop\update.zip"
Dim za As ZipArchive = ZipFile.Open(zipfile, ZipArchiveMode.Read)
For Each entrie As ZipArchiveEntry In za.Entries
MessageBox.Show(entrie.Name)
Next
راح يطبع لي في كل مرة اسم ملف في الملف المضغوط
حيث ان مصطلح Entries يعبر عن الملفات التي بداخل الملف المضغوط
-
لو حبيت تعرف حجم ملف معين داخل الملف المضغوط :-
PHP كود :
Const zipfile As String = "C:\Users\Fti\Desktop\update.zip"
Dim za As ZipArchive = ZipFile.Open(zipfile, ZipArchiveMode.Read)
Dim ae As ZipArchiveEntry = za.Entries.Where(Function(n) n.Name = "update.xml").FirstOrDefault()
MessageBox.Show(ae.Length.ToString())
--
عمل استخراج لملف معين وليكن اسمه update.xml :
PHP كود :
Const zipfile As String = "C:\Users\Fti\Desktop\update.zip"
Dim za As ZipArchive = ZipFile.Open(zipfile, ZipArchiveMode.Read)
Dim ae As ZipArchiveEntry = za.Entries.Where(Function(n) n.Name = "update.xml").FirstOrDefault()
ae.ExtractToFile("c:/update.xml")
--
لو حبيت تجيب بيانات الملف لوحده دون عمل استخراج (يعني جلب bytes) له :-
PHP كود :
Dim fileData As Byte()
Const zipfile As String = "C:\Users\Fti\Desktop\update.zip"
Dim za As ZipArchive = ZipFile.Open(zipfile, ZipArchiveMode.Read)
Dim ae As ZipArchiveEntry = za.Entries.Where(Function(n) n.Name = "update.xml").FirstOrDefault()
fileData = New Byte(ae.Length) {}
Dim st As Stream = ae.Open()
st.Read(fileData, 0, fileData.Length)
'now fileData variable is store update.xml data
--
لو حبيت تعرف حجم الملف update.xml بعد ان تم ضغطه اي (Compression size) :-
PHP كود :
Const zipfile As String = "C:\Users\Fti\Desktop\update.zip"
Dim za As ZipArchive = ZipFile.Open(zipfile, ZipArchiveMode.Read)
Dim ae As ZipArchiveEntry = za.Entries.Where(Function(n) n.Name = "update.xml").FirstOrDefault()
MessageBox.Show(ae.CompressedLength.ToString())
الاكواد محولة من السي شارب - يمكن فيها غلط