Icsharpziplib

Using icsharpziplib,

http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx


I am trying to pass a stream from a file control into an array of bytes and then zip the stream somehow...im using this code below...and the data im receiving is corrupt..


>>File1 is file control...

Dim imgLen As Integer
Dim imgName_value As String
Dim imgContentType As String
Dim imgUploadedName As String
Dim imgName As String

Dim stmGzipArchive As New ZipInputStream(File.OpenRead(File1.PostedFile.FileName))

imgLen = stmGzipArchive.Length
imgUploadedName = file1.PostedFile.FileName
Dim imgBinaryData(imgLen) As Byte
imgContentType = file1.PostedFile.ContentType
imgName_value = imgName

stmGzipArchive.Read(imgBinaryData, 0, imgLen)



Moiz
LVL 4
Moizsaif123Asked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
Arrays in .NET are 0-based, so try this instead:

imgLen = stmGzipArchive.Length
imgUploadedName = file1.PostedFile.FileName
Dim imgBinaryData(imgLen - 1) As Byte                 <<<<<<< Length - 1
imgContentType = file1.PostedFile.ContentType
imgName_value = imgName

stmGzipArchive.Read(imgBinaryData, 0, imgLen)

Otherwise, the last byte will be a 0, which is not what you want.

Bob
0
 
Moizsaif123Author Commented:
I use this code below...and the output i get are in all this ..

0 0 0 0 0 0 ....

0 0 0 0 0 0 ....

0 0 0 0 0 0 ....


        Dim imgLen As Integer
        Dim s As Stream = New ZipInputStream(file1.PostedFile.InputStream)

        imgLen = s.Length
        imgUploadedName = "C:\Inetpub\wwwroot\WebApplication21\WebForm2.aspx"
        Dim imgBinaryData(imgLen - 1) As Byte
        imgContentType = file1.PostedFile.ContentType
        imgName_value = imgName

        s.Read(imgBinaryData, 0, s.Length)

        Dim NumRowsAffected As Integer = MyDatabaseMethod _
        (imgBinaryData)
0
 
Bob LearnedCommented:
The file name is an ASP.NET page, and not a .zip file.

Bob
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Moizsaif123Author Commented:
       
no forget that line of code..this is the actual code where i call any file from the file control....

        Dim imgLen As Integer
        Dim s As Stream = New ZipInputStream(file1.PostedFile.InputStream)

        imgLen = s.Length
        Dim imgBinaryData(imgLen - 1) As Byte
        imgContentType = file1.PostedFile.ContentType
        imgName_value = imgName

        s.Read(imgBinaryData, 0, s.Length)

        Dim NumRowsAffected As Integer = MyDatabaseMethod _
        (imgBinaryData)


0
 
Moizsaif123Author Commented:
this site helps and seeing this section...

How do I compress/decompress files in memory?



http://wiki.sharpdevelop.net/default.aspx/SharpZipLib.FrequentlyAskedQuestions
0
 
Moizsaif123Author Commented:
0
 
Moizsaif123Author Commented:
<%@ Language=VBScript %>
<% option explicit %>
<html>
<head>
<meta name="GENERATOR" Content="Microsoft Visual Studio.NET 7.0">
</head>
<body>
<%
dim conn, Connection, Ssql
conn = "data source=MOIZ-L0SAQBQZDF;database=emp;persist security info=False;user id=sa;Password=sa;workstation id=MOIZ-L0SAQBQZDF;packet size=4096"
set Connection = server.CreateObject("ADODB.Connection")
Connection.Open(conn)
Ssql = "select * from mytable"
set rowset = Connection.Execute(Ssql)
response.write(rowset("i"))
conn.close

%>


</body>
</html>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.