473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Downloading Zip from SQL Image field

I'm converting a Delphi app to C#. The application uploads and downloads
files to an image field on SQL through a webservice. With Delphi, this was
done straight to SQL instead of a webservice. The C# code works fine in both
directions except in the case of zip files. I get a message, from WinZip,
telling me that the archive is not valid. The zip is valid, in the sql
server, becuase it can be opened when using my old Delphi version of this
program. I can also upload the zips with the C# version and open them with
the Delphi version so I'm pretty sure it how the file is being re-created
using C#.

Below is the code that I use to download and open the file Any help would be
appreciated.

TIA

//Get the document from the table
DataRow rowDataImage = null;
DataRowView rowData =
DataRowView)BindingContext[dsLibrary.Tables["AvailDocs"]].Current;
DataSet ds = DB.getDoc(System.Convert.ToInt32(rowData[0].ToString()));
string strDocExt =
DB.getDocFileExt(System.Convert.ToInt32(rowData[0].ToString()));
rowDataImage=ds.Tables[0].Rows[0];

//Read the image from the table field into a byte array
byte[] MyData= new byte[0];
MyData = (byte[])rowDataImage[0];
int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0);

//Create a destination for the file
FileStream fs = new FileStream("c:\\elibtemp." + strDocExt,
FileMode.Create,FileAccess.Write,FileShare.Write,A rraySize,true);

// Create the writer for data.
fs.Write(MyData, 0,ArraySize);
fs.Close();
Dec 23 '05 #1
1 1645
Hi,

No idea if this is related or not, but in my office computer I have a
similar error, each time I select to download something from the internet
and select "open" instead of "save" I get the same error, but if I save it
first and open later I have no problem at all. I had no time to investigate
why is this happening, maybe the antivirus or a security policy.

Btw, the code seems fine , you did not post it how you are getting it from
the DB but it should be fine too.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"jo**@nospam.com" <jo**@nospam.com@discussions.microsoft.com> wrote in
message news:21**********************************@microsof t.com...
I'm converting a Delphi app to C#. The application uploads and downloads
files to an image field on SQL through a webservice. With Delphi, this was
done straight to SQL instead of a webservice. The C# code works fine in
both
directions except in the case of zip files. I get a message, from WinZip,
telling me that the archive is not valid. The zip is valid, in the sql
server, becuase it can be opened when using my old Delphi version of this
program. I can also upload the zips with the C# version and open them with
the Delphi version so I'm pretty sure it how the file is being re-created
using C#.

Below is the code that I use to download and open the file Any help would
be
appreciated.

TIA

//Get the document from the table
DataRow rowDataImage = null;
DataRowView rowData =
DataRowView)BindingContext[dsLibrary.Tables["AvailDocs"]].Current;
DataSet ds = DB.getDoc(System.Convert.ToInt32(rowData[0].ToString()));
string strDocExt =
DB.getDocFileExt(System.Convert.ToInt32(rowData[0].ToString()));
rowDataImage=ds.Tables[0].Rows[0];

//Read the image from the table field into a byte array
byte[] MyData= new byte[0];
MyData = (byte[])rowDataImage[0];
int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0);

//Create a destination for the file
FileStream fs = new FileStream("c:\\elibtemp." + strDocExt,
FileMode.Create,FileAccess.Write,FileShare.Write,A rraySize,true);

// Create the writer for data.
fs.Write(MyData, 0,ArraySize);
fs.Close();

Dec 27 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave | last post by:
Dear Sirs, Is there a way to get the width and height of an image without downloading the image, or with just downloading a minimal portion of the image? For instance, I have a list of 10,000...
4
by: Himanshu | last post by:
hi, Can anybody tell me that thru asp.net using c#, how can we upload and download physical files in any table of SQL Server Database. the uploading part is running successfully but the...
23
by: Doug van Vianen | last post by:
Hi, Is there some way in JavaScript to stop the downloading of pictures from a web page? Thank you. Doug van Vianen
5
by: Trapulo | last post by:
Hi, I've a big trouble with an asp.net page. Basically, the page has an swf that starts and downloads some data from an other asp.net page. The application works well on my testing IIS 6, but...
6
by: Dustan | last post by:
Nobody answered last time. I guess they wanted me to give it a shot. Well, here is how I download the image (it's a class method): def download_image(self):...
4
by: aldonnelley | last post by:
Hi there: a bit of a left-field question, I think. I'm writing a program that analyses image files downloaded with a basic crawler, and it's slow, mainly because I only want to analyse files...
2
archulu
by: archulu | last post by:
hai this is archulu, i have a some confusion and doubt in my downloading program.that doubt was in my program i am upload some gif and img file to some path.it's good, after usage of that image i...
4
by: surja | last post by:
Hi, I have written a code to download images from a server end desktop, but while running the code ,WTK is showing a runtime error " Create image from Byte array Uncaught exception...
1
by: shahidrasul | last post by:
i want to download a file which user select from gridview, downloading is completing without problem but after download i want to refresh my page because i do some changes in db . but when...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.