locked
Zip / Unzip in vb.net . FileStream Problem ! RRS feed

  • Question

  • User-1328385175 posted

    hi.

     i had tried to compress my folder by this code.

    Imports System.IO
    Imports System.IO.Compression
    Module Module1
    
        Sub Main()
            ' Path to directory of files to compress.
            Dim dirpath As String = "c:\users\pubic\reports"
    
            Dim di As DirectoryInfo = New DirectoryInfo(dirpath)
    
            ' Compress the directory's files.
            For Each fi As FileInfo In di.GetFiles()
                Compress(fi)
            Next
    
            ' Decompress all *.cmp files in the directory.
            For Each fi As FileInfo In di.GetFiles("*.cmp")
                Decompress(fi)
            Next
    
        End Sub
    
        ' Method to compress.
        Private Sub Compress(ByVal fi As FileInfo)
            ' Get the stream of the source file.
            Using inFile As FileStream = fi.OpenRead()
                ' Compressing:
                ' Prevent compressing hidden and already compressed files.
    
                If (File.GetAttributes(fi.FullName) And FileAttributes.Hidden) _
                    <> FileAttributes.Hidden And fi.Extension <> ".cmp" Then
                    ' Create the compressed file.
                    Using outFile As FileStream = File.Create(fi.FullName + ".cmp")
                        Using Compress As DeflateStream = New DeflateStream(outFile, _
                                                            CompressionMode.Compress)
                            ' Copy the source file into the compression stream.
                            inFile.CopyTo(Compress)
    
                            Console.WriteLine("Compressed {0} from {1} to {2} bytes.", _
                              fi.Name, fi.Length.ToString(), outFile.Length.ToString())
    
                        End Using
                    End Using
                End If
            End Using
        End Sub
    
        ' Method to decompress.
        Private Sub Decompress(ByVal fi As FileInfo)
            ' Get the stream of the source file.
            Using inFile As FileStream = fi.OpenRead()
                ' Get orignial file extension, for example "doc" from report.doc.cmp.
                Dim curFile As String = fi.FullName
                Dim origName = curFile.Remove(curFile.Length - fi.Extension.Length)
    
                ' Create the decompressed file.
                Using outFile As FileStream = File.Create(origName)
                    Using Decompress As DeflateStream = New DeflateStream(inFile, _
                                                            CompressionMode.Decompress)
    
                		' Copy the decompression stream into the output file.
                		Decompress.CopyTo(outFile)
                		
                        Console.WriteLine("Decompressed: {0}", fi.Name)
    
                    End Using
                End Using
            End Using
        End Sub
    End Module
    
    

    this code is from : http://msdn.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx

    but at 

     inFile.CopyTo(Compress) 
    I have some error message like this :
    'copyto' is not a member of 'system.io.filestream'

    and at line of :
    Decompress.CopyTo(outFile)
    there are some error like this :
    'copyto' is not a member of 'system.io.compression.deflateStream'


    Please help me to solve thats problems ... Cry
    Friday, July 16, 2010 11:47 PM

Answers

  • User197322208 posted

    'copyto' is not a member of 'system.io.filestream'

    strange, because it is

    http://msdn.microsoft.com/en-us/library/dd782932.aspx

    in .NET 4 ;-)

    . Are you using .NET 3.5 ?


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 18, 2010 12:05 AM

All replies

  • User197322208 posted

    'copyto' is not a member of 'system.io.filestream'

    strange, because it is

    http://msdn.microsoft.com/en-us/library/dd782932.aspx

    in .NET 4 ;-)

    . Are you using .NET 3.5 ?


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 18, 2010 12:05 AM
  • User-1328385175 posted

    yes . I work with 3.5.

    But, Please see at bottom of http://msdn.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx .


    Version Information

    .NET Framework

    Supported in: 4, 3.5, 3.0, 2.0

    .NET Framework Client Profile

    Supported in: 4, 3.5 SP1

    Do you know what i have to do for solve this problem ? I need some Example from 3.5 !!!


    Sunday, July 18, 2010 10:43 PM
  • User-371606616 posted

    Using .net 3.5 SP1. I am having the same problem. What is the fix?

    Friday, April 15, 2011 1:16 PM