[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Icsharpziplib

Posted on 2005-05-17
8
Medium Priority
?
2,175 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:Moizsaif123
  • 5
  • 2
7 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 400 total points
ID: 14027403
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
 
LVL 4

Author Comment

by:Moizsaif123
ID: 14027676
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 14027740
The file name is an ASP.NET page, and not a .zip file.

Bob
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
LVL 4

Author Comment

by:Moizsaif123
ID: 14027855
       
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
 
LVL 4

Author Comment

by:Moizsaif123
ID: 14028689
this site helps and seeing this section...

How do I compress/decompress files in memory?



http://wiki.sharpdevelop.net/default.aspx/SharpZipLib.FrequentlyAskedQuestions
0
 
LVL 4

Author Comment

by:Moizsaif123
ID: 14028828
0
 
LVL 4

Author Comment

by:Moizsaif123
ID: 14220983
<%@ 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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question