Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...SharpZipLib.dll: How can I use it?SharpZipLib.dll: How can I use it?
Previous
 
Next
New Post
4/6/2007 6:57 AM
 

Hi,

I want to be able to take a file and zip it up so that my website users have that compressed format for downloading.

I note that DNN has the SharpZipLib library in the \bin directory and I believe I can make calls to that to do this job.... Is there any Dotnetnuke information on this?

regards,
Duncan.

 
New Post
4/6/2007 7:31 AM
 

...... I've answered my own question :)

The following code should do it.... [Untested yet].

1. Add the SharpZipLib from the \bin library to the reference section of your local project [If not already there....]
2. Add the folowing imports [C#: using].... at the head of the file

3. Add the following code:

 Public Function CreateZipFile(ByVal strFile As String, ByVal targetName As String) As Boolean
CreateZipFile = false
Try
    Dim strmZipOutputStream As ZipOutputStream
    strmZipOutputStream = New ZipOutputStream(File.Create(targetName))
    ' Compression Level: 0-9, 0: no(Compression), 9: maximum compression
    strmZipOutputStream.SetLevel(9)
    Dim strmFile As FileStream = File.OpenRead(strFile)
    Dim abyBuffer(strmFile.Length - 1) As
Byte
    strmFile.Read(abyBuffer, 0, abyBuffer.Length)

    Dim objZipEntry As ZipEntry = New ZipEntry(strFile)
    objZipEntry.DateTime = DateTime.Now
    objZipEntry.Size = strmFile.Length
    strmFile.Close()
    strmZipOutputStream.PutNextEntry(objZipEntry)
    strmZipOutputStream.Write(abyBuffer, 0, abyBuffer.Length)
    strmZipOutputStream.Finish()
    strmZipOutputStream.Close()
   CreateZipFile = True

    Catch
ex As Exception 
        DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(Me, ex)
    End
Try

End Function

 


My thanks to JohnR of SharpDevelop who provided the baseline for this snippet. the SharpLib documentation and C#/VB samples can be found at http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx

 

 

 

Imports System.IO
Imports ICSharpCode.SharpZipLib.Zip

 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...SharpZipLib.dll: How can I use it?SharpZipLib.dll: How can I use it?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out