添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim startPath As String = "D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Vessel_Composition\compositionVIRZIP.csv" Dim zipPath As String = "D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Zipped\test.zip" Dim extractPath As String = "D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Unzipped" ZipFile.CreateFromDirectory(startPath, zipPath) ZipFile.ExtractToDirectory(zipPath, extractPath) MsgBox("Done") End Sub End Class But I get the following error : System.IO.IOException: 'The parameter is incorrect. : 'D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Vessel_Composition\compositionVIRZIP.csv''
From https://docs.microsoft.com/en- I can see a @ is placed before the file description, but how to do it in VB.Net?
I have both System.IO.Compression and System.IO.Compression.ZipFile installed via NuGet.
I am using .NET 5.0
Regards Firstly, the @ symbol is irrelevant to VB. That indicates a verbatim string literal in C#, which means that the backslash character is considered to be a literal character like any other, rather than an escape character. Basically, instead of doing this:
csharp Code:
  1. var filePath = "C:\\folder\\subfolder\\file.ext";
you can do this:
csharp Code:
  1. var filePath = @"C:\folder\subfolder\file.ext";
The backslash character isn't an escape character in VB to begin with, so there's no need to specify that it's not.
Secondly, you should not have seen that in the first place when reading the Microsoft Docs site. That site defaults to C# code examples but you can select a different language at the top of any page and that will persist whenever you use the site. If you select VB there then you will always see VB examples whenever they are available.
As for the issue, if you are calling a method named ZipFile.CreateFromDirectory then what do you think the path you pass it as the source should refer to? Probably the directory you want to create the ZIP file from, right? The parameter is even named sourceDirectoryPath . Is that what you're doing? No, it is not. You're passing the path of a file, which is not a directory, thus that parameter is incorrect.
By the way, I just tested code like yours in a VB WinForms .NET 5.0 app and I didn't have to add any NuGet packages. Microsoft.NETCore.App was listed under Dependencies\Frameworks and System.IO.Compression.ZipFile was listed under that. I know that you can specify that a .NET Core app relies on an installed framework or brings its dependencies with it but I haven't played around with that as yet. Did you specify that your app would provide its own dependencies specifically?
Thank you jmchilhinney. Yes I was incorrectly passing a file in stead of a directory.
From what I read I then take it one cannot compress a single file in a directory. Everything gets compressed into a archive. From this archive one then can use the ZipArcive.GetEntry to extract a single file. My problem is that I need to create a .zip file on a daily basis - so I want to keep the zipped archive as small as possible.
I guess I have to make sure only a single .csv file is in the directory?
Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.