|
-
Jul 20th, 2010, 08:07 PM
#1
Thread Starter
Junior Member
[RESOLVED] Using embedded DLL's/Extracting .ZIP's
Hi all, another few questions.
I am using DotNetZip for use of extracting a .ZIP from the resources. When I run the standalone .EXE, errors appear about a missing DLL, so I added it into the resources via the properties panel, but I still get the same error. How do I use the embedded .DLL?
Another question, might be the wrong place to ask it but I am having problems extracting 'Conroy.zip' from my resources using DotNetZip. If anyone could show me the code or give advice, it would be greatly appreciated.
Thanks,
-Conroy.
-
Jul 20th, 2010, 08:09 PM
#2
Re: Using embedded DLL's/Extracting .ZIP's
Are you copying the DotNetZip DLL file to the same directory as your exe?
-
Jul 21st, 2010, 09:20 AM
#3
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
 Originally Posted by formlesstree4
Are you copying the DotNetZip DLL file to the same directory as your exe?
Yes, at the moment I am, and it works fine, but I want to send this program to other people as a standalone .EXE, hence why I am wondering how to use it as an embedded resource.
Thanks,
-Conroy
-
Jul 21st, 2010, 12:25 PM
#4
Re: Using embedded DLL's/Extracting .ZIP's
You would still have to have it present. Visual Basic isn't going to read the EXE to find the DLL, it's going to want it either in the GAC or right next to the EXE.
-
Jul 21st, 2010, 12:51 PM
#5
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
Alright, I will put it in the same folder when I give it out to people.
What about the DotNetZip, anyone have any knowledge of that? I thought I might ask that while I'm here. If not, I'll go onto their website and ask.
Thanks,
-Conroy
-
Jul 21st, 2010, 01:12 PM
#6
Re: Using embedded DLL's/Extracting .ZIP's
I'm not familiar with DotNetZip but I do know about reading resources out of your app using a memory stream and I doubt you can pass a memory stream to DotNetZip, which if true means you'd need to extract the zip file to the user's temp folder (you can delete it when done extracting from it) then pass the file path to the DotNetZip extract method and go from there.
-
Jul 21st, 2010, 01:52 PM
#7
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
 Originally Posted by JuggaloBrotha
I'm not familiar with DotNetZip but I do know about reading resources out of your app using a memory stream and I doubt you can pass a memory stream to DotNetZip, which if true means you'd need to extract the zip file to the user's temp folder (you can delete it when done extracting from it) then pass the file path to the DotNetZip extract method and go from there.
Yes, I was thinking about doing that. Thanks for the reply.
I wont 'resolve' the thread yet, I might need further assistance.
Thanks again,
-Conroy
-
Jul 21st, 2010, 02:37 PM
#8
Re: Using embedded DLL's/Extracting .ZIP's
If DotNetZip doesn't accept memory streams, that's pretty lame. I use SharpZipLib, all it wants is a stream.. doesn't care if it's a memory stream, file stream or what, as long as it is a stream. In fact, my use of it makes heavy use of memory streams, zipping and unzipping the data.
-tg
-
Jul 21st, 2010, 02:40 PM
#9
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
Does the library support zipping to a stream? Or unzipping from a stream?
Yes, you can zip up files and Save the zip archive to a stream. As well you can Read a zip archive from an open stream - I use this for embedded resources in apps: I call GetManifestResourceStream(), and then unzip that resource. Reading and writing streams complements the capability of being able to Save to a plain file or read from a plain file. The Save-to-a-stream capability allows you to write a zip archive out to, for example, the ASP.NET Response.Output stream, without creating an intermediate file. Very nice for ASP.NET applications.
I just found out it does support Stream, but I am unsure how to do it. It sounds complicated and I find it easier just moving the .ZIP to a temp folder. On the other hand, if you would like to show me how Stream, be my guest. 
Thanks,
-Conroy
-
Jul 21st, 2010, 02:45 PM
#10
Re: Using embedded DLL's/Extracting .ZIP's
Ok, so when you use the memory stream to extract the file from the resources instead of passing it to a FileStream (to write it to the hard drive) pass it to the dll for extraction.
-
Jul 21st, 2010, 02:53 PM
#11
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
 Originally Posted by JuggaloBrotha
Ok, so when you use the memory stream to extract the file from the resources instead of passing it to a FileStream (to write it to the hard drive) pass it to the dll for extraction.
Could you show me an example? The .ZIP is named 'Conroy.zip'.
-
Jul 21st, 2010, 02:54 PM
#12
Re: Using embedded DLL's/Extracting .ZIP's
Take a look at FileStreams at MSDN.
-
Jul 21st, 2010, 03:04 PM
#13
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
Code:
Dim fs As FileStream = Me.GetType().Assembly.GetManifestResourceStream("Conroy.zip")
Using zip1 As ZipFile = ZipFile.Read(fs)
Returns null, any ideas?
-
Jul 21st, 2010, 03:09 PM
#14
Re: Using embedded DLL's/Extracting .ZIP's
Something like this:
Code:
Using s As Stream = Me.GetType().Assembly.GetManifestResourceStream(Me.GetType(), "Conroy.zip")
'Pass "s" to the zip dll thing
End Using
-
Jul 21st, 2010, 03:28 PM
#15
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
I appreciate your help.
Code:
Using s As Stream = Me.GetType().Assembly.GetManifestResourceStream(Me.GetType(), "Conroy.zip")
For Each File In s
File.Extract("C:\Users\Dale\Desktop", ExtractExistingFileAction.OverwriteSilently)
Next
End Using
Error 1: Expression is of type 'System.IO.Stream', which is not a collection type.
-
Jul 21st, 2010, 03:34 PM
#16
Re: Using embedded DLL's/Extracting .ZIP's
s is the stream itself, you pass the stream to the dll and let the dll extract the files from the zip file.
-
Jul 21st, 2010, 03:35 PM
#17
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
Could you show me another example, please? Sorry to bother you, I just don't understand it.
Thanks,
-Conroy.
-
Jul 21st, 2010, 03:39 PM
#18
Fanatic Member
Re: Using embedded DLL's/Extracting .ZIP's
If you dont want to use 3rd party .ZIP tools, you can use the built in to windows, shell32.dll
check out the link in my signature about Extracting/Zipping using shell32
PS: its so much easier.
-
Jul 21st, 2010, 03:43 PM
#19
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
I know how to extract zip's on my hard drive, so that's not a problem, it's just using them from my resources which confuses me.
-Conroy
-
Jul 21st, 2010, 09:18 PM
#20
Re: Using embedded DLL's/Extracting .ZIP's
conroy, without me having the dll here to work with, I can't really provide any more info than I already have. Besides if you follow what's been said in this thread, it shouldn't be very difficult to pass the stream to the unzipping function (which you say it supports) and I've shown how to get the stream, so just pass it in.
-
Jul 22nd, 2010, 11:57 AM
#21
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
I do understand that for some more experienced VS2010 VB programmers, it would be easy to understand about passing streams to the dll, but I just recently got VS2010 and have never handled dll's before. I used to use VB6 to make very simple programs, and this is a big step for me. I would appreciate more simple help. 'pass the stream to the dll' is new for me, I have no clue how to do this. If you or anyone else can simplify this down for a beginner to understand, it would be a whole lot better for me to take in and learn.
Thanks,
-Conroy
-
Jul 22nd, 2010, 12:16 PM
#22
Re: Using embedded DLL's/Extracting .ZIP's
You know how to pass something to another thing, in post #15 you posted your code:
File.Extract("C:\Users\Dale\Desktop", ExtractExistingFileAction.OverwriteSilently)
Where you're trying to pass "C:\Users\Dale\Desktop" and ExtractExistingFileAction.OverwriteSilently to the File.Extract method, which is in the dll. So instead of passing "C:\Users\Dale\Desktop" to it, pass it s (the stream) instead. Though it may be a different method call that takes the stream, which I couldn't tell you any more than that because I dont have the dll, I dont know what methods (and arguments) it takes. Someone would have to send me the dll before I could answer anything else at this point.
-
Jul 22nd, 2010, 12:38 PM
#23
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
Sent you a PM.
The function is File.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)
-
Jul 22nd, 2010, 01:02 PM
#24
Re: Using embedded DLL's/Extracting .ZIP's
OK... there is a LOT of confusion here on what is what...
http://dotnetzip.codeplex.com/
The zipped file is in a resource, correct?
OK.. so... what you need is to get a stream that contains the data of the resource, and feed it to the DotNetZip object that represents the zipped file. At this point, we aren't even to "File.Extract" level yet... so let's not worry about it.
From the CodePlex page where the project is hosted, is this sample code:
Code:
Dim ZipToUnpack As String = "C1P3SML.zip"
Dim TargetDir As String = "C1P3SML"
Console.WriteLine("Extracting file {0} to {1}", ZipToUnpack, TargetDir)
Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress
Dim e As ZipEntry
' here, we extract every entry, but we could extract
' based on entry name, size, date, etc.
For Each e In zip1
e.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)
Next
End Using
OK... so now, let's modify that to work with a stream. PLEASE NOTE: this is untested.
vb Code:
' This creates the stream from the resource Using s As Stream = Me.GetType().Assembly.GetManifestResourceStream(Me.GetType(), "Conroy.zip") Dim TargetDir As String = "C1P3SML" 'Naturally adjust this to suit your needs. Using zip1 As ZipFile = ZipFile.Read(s) 'as Juggalo stated: Pass "s" to the zip dll thing AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress ' I'm guessing this is optional if you want to show progress.... Dim e As ZipEntry ' here, we extract every entry, but we could extract ' based on entry name, size, date, etc. For Each e In zip1 e.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently) ' This is what will actually write your files out Next End Using 'zip1 End Using 'Stream
By the time you get to File.Extract, you should have already read the stream to the archive file. The File.Extract has nothing to do with the stream by that point.
-tg
side note - took me less than 3 minutes to look all that info up and put it together. it isn't rocket science.
-
Jul 22nd, 2010, 01:27 PM
#25
Re: Using embedded DLL's/Extracting .ZIP's
conroy, I got your PM and what TG has already posted here is what I was talking about (even though I didn't have the actual dll, nor the codeplex website to reference)
-
Jul 22nd, 2010, 01:31 PM
#26
Thread Starter
Junior Member
Re: Using embedded DLL's/Extracting .ZIP's
Finally, it works with that code. Hopefully I'll know in the future, thanks both of you.
-Conroy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|