我遇到an article在VS2013中实现.zip VB文件压缩,但实现它时遇到了麻烦。
当我到达System.IO.Compression.ZipFile.CreateFromDirectory
行时,我在VS中遇到一个错误,即.ZipFile不是“.Compression”的成员。
这是我的命令按钮的代码(使用user3688529的代码),名为zipButton,listbox名为filesListBox:
Private Sub zipButton_Click(sender As Object, e As EventArgs) Handles zipButton.Click
'Button click events.
'Start backup.
Dim PjtPath As String = TextBox1.Text
Dim ZipLocal As String = TextBox2.Text
Dim ZipNetwk As String = TextBox3.Text
Static Dim StartPath As String
Static Dim ZipPath As String
For Each a As String In filesListBox.SelectedItems()
'Dim PjtName As String = ListBox1.SelectedItems(a).ToString
Dim PjtName As String = a
Dim ZipExt As String = Format(Now, " yyyy-MM-dd @ HHmm") & ".zip"
If TextBox2.Text = String.Empty Then
StartPath = PjtPath & "\" & PjtName
ZipPath = PjtPath & "\" & PjtName & ZipExt
ElseIf TextBox2.Text <> String.Empty Then
StartPath = PjtPath & "\" & PjtName
ZipPath = ZipLocal & "\" & PjtName & ZipExt
End If
System.IO.Compression.ZipFile.CreateFromDirectory _
(StartPath, ZipPath, IO.Compression.CompressionLevel.Optimal, True)
If TextBox3.Text <> String.Empty Then
Dim ZipCopy As String = ZipNetwk & "\" & PjtName & ZipExt
My.Computer.FileSystem.CopyFile(ZipPath, ZipCopy)
End If
Next
End Sub
是否需要包含一些模块才能使.ZipFle成员可以访问?
答案 0 :(得分:0)
您可能需要在项目引用中添加对System.IO.Compression.FileSystem的引用。 “项目 - &gt;添加参考”。在Framework下,找到System.IO.Compression.FileSystem。