Hi
I'm new to SharpZipLib so pleased excuse any crazy errors!
I have to write a function to zip and password protect a single file. The following code works correctly - when run directly from a vb.net (2005) form. I can extract the zipped file from just windows compress folders, or 7-Zip file manger, or WinZip - so no problem there. ( I've also used the ZipOutputStream - with no problems.)
--------------
Dim oZip As New ICSharpCode.SharpZipLib.Zip.FastZip '(_ZipEvents)
Dim spwd As String = "password"
Dim sfolder As String = "c:\temp\macs\singlefile"
Dim sDestfile As String = "c:\temp\createziptest6.zip"
oZip.CreateEmptyDirectories =
False
oZip.Password = spwd
'"password"
oZip.CreateZip(sDestfile, sfolder,
False, "", "")
oZip =
Nothing
-------
However - if i wrap the code in a class - I cannot extract any files correctly. All give me the "incorrect password" error. This is wrong - since the password is correct!
The function below is used in my wrapper class - and to all intense and purposes its the same! Please can anyone shed any light on this for me?
I'm using build 0.85.3.365 of the library, running with VS2005.net professional, windows XP profession - (with windows update switched on)
thanks in advance!
Lewin
Friend Function FastZip(ByVal sSourceFileName As String, Optional ByVal sPassword As String = "") As ReturnValuesEnum
Dim sDest As String = System.IO.Path.ChangeExtension(sSourceFileName, ".zip")
Dim eRet As ReturnValuesEnum = ReturnValuesEnum.rvFalse
Dim oZip As New ICSharpCode.SharpZipLib.Zip.FastZip
Dim strSourceFolder As String = My.Computer.FileSystem.GetParentPath(sSourceFileName)
Dim strNameOnly As String = My.Computer.FileSystem.GetName(sSourceFileName)
Dim strlocalPW As String = sPassword
Try
If My.Computer.FileSystem.FileExists(sDest) Then
My.Computer.FileSystem.DeleteFile(sDest)
End If
oZip.CreateEmptyDirectories =
False
oZip.Password = strlocalPW
'"password" 'sPassword
oZip.CreateZip(sDest, strSourceFolder,
False, strNameOnly, "")
eRet = ReturnValuesEnum.rvTrue
Catch ex As Exception
_ZipException = ex
eRet = ReturnValuesEnum.rvError
Finally
oZip =
Nothing
End Try
Return eRet
End Function