473,770 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

does anyone see what is wrong with my .gif download logic? no matter what image url i try it downloads a junk file that can't be opened in any paint program.

dr
does anyone see what is wrong with my .gif download logic? no matter what
image url i try it downloads a junk file that can't be opened in any paint
program.
System.Net.WebR equest myRequest = System.Net.WebR equest.Create(u rl);
System.Net.WebR esponse myResponse = myRequest.GetRe sponse();
System.IO.Strea m imgStream = myResponse.GetR esponseStream() ;
long len = myResponse.Cont entLength;
byte[] binarydata = new byte[len];
System.IO.Strea m streambinary = myResponse.GetR esponseStream() ;
streambinary.Re ad(binarydata, 0, (int)len);
using(System.IO .BinaryWriter binWriter = new
System.IO.Binar yWriter(System. IO.File.Open(@" C:\foo.gif",
System.IO.FileM ode.Create)))
{
binWriter.Write (binarydata, 0, (int)len);
}


Feb 19 '07 #1
6 1530
dr wrote:
does anyone see what is wrong with my .gif download logic? no matter what
image url i try it downloads a junk file that can't be opened in any paint
program.
System.Net.WebR equest myRequest = System.Net.WebR equest.Create(u rl);
System.Net.WebR esponse myResponse = myRequest.GetRe sponse();
System.IO.Strea m imgStream = myResponse.GetR esponseStream() ;
long len = myResponse.Cont entLength;
byte[] binarydata = new byte[len];
System.IO.Strea m streambinary = myResponse.GetR esponseStream() ;
streambinary.Re ad(binarydata, 0, (int)len);
using(System.IO .BinaryWriter binWriter = new
System.IO.Binar yWriter(System. IO.File.Open(@" C:\foo.gif",
System.IO.FileM ode.Create)))
{
binWriter.Write (binarydata, 0, (int)len);
}
You read the data from the stream without considering the result. The
Read method returns an integer that is the number of bytes actually
read, which may be smaller than the number of bytes requested.

When you read the data, the buffer will only be partially filled with
data, then you save the entire buffer as if it all contained valid data.
This will produce a broken file.

You have to get the return value from the Read call and use that to
determine how much data you have gotten, and loop until you have got all
the data.

--
Göran Andersson
_____
http://www.guffa.com
Feb 19 '07 #2
Please don't multipost.
Feb 19 '07 #3
Michael C wrote:
>Please don't multipost.
One should think, this kind of reply would only be necessary in one group and not both...

--
Thomas Due
Posted with XanaNews version 1.18.1.6

"A military operation involves deception. Even though you are
competent, appear to be incompetent. Though effective, appear
to be ineffective."
-- Sun-tzu, The Art of War. Strategic Assessments
Feb 19 '07 #4
Hi,

"dr" <so************ *******@yahoo.c omwrote in message
news:eV******** ********@TK2MSF TNGP06.phx.gbl. ..
does anyone see what is wrong with my .gif download logic? no matter what
image url i try it downloads a junk file that can't be opened in any paint
program.
Use this code

HttpWebRequest request = (HttpWebRequest ) WebRequest.Crea te(
"http://www..com/update.zip");
HttpWebResponse response =(HttpWebRespon se) request.GetResp onse();
Stream source = response.GetRes ponseStream();
string targetFile = Config.CodeBase + "\\" +
DateTime.Now.Ti cks.ToString() + ".zip";
FileStream writer = new FileStream( targetFile, FileMode.Create );
byte[] buffer = new byte[4098];
int readed=0;
while( (readed=source. Read( buffer, 0, 4098))>0)
{
writer.Write( buffer, 0, readed);
}
writer.Close();
source.Close();
Feb 19 '07 #5
"Thomas Due" <tdue@mail_remo ve_.dkwrote in message
news:%2******** **********@TK2M SFTNGP02.phx.gb l...
One should think, this kind of reply would only be necessary in one group
and not both...
Shouldn't both groups know that maybe the question has been answered
elsewhere?

--
Thomas Due
Posted with XanaNews version 1.18.1.6

"A military operation involves deception. Even though you are
competent, appear to be incompetent. Though effective, appear
to be ineffective."
-- Sun-tzu, The Art of War. Strategic Assessments
Feb 19 '07 #6
On Mon, 19 Feb 2007 06:09:25 -0800, "Thomas Due" <tdue@mail_remo ve_.dkwrote:
>Michael C wrote:
>>Please don't multipost.

One should think, this kind of reply would only be necessary in one group and not both...
Long live Sun-tzu
and Clausewitz too.

Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com
Feb 20 '07 #7

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

Similar topics

6
3018
by: Juho Saarikko | last post by:
The program attached to this message makes the Python interpreter segfault randomly. I have tried both Python 2.2 which came with Debian Stable, and self-compiled Python 2.3.3 (newest I could find on www.python.org, compiled with default options (./configure && make). I'm using the pyPgSQL plugin to connect to a PostGreSQL database, and have tried the Debian and self-compiled newest versions of that as well. I'm running BitTorrent, and...
6
18938
by: Glenn Owens | last post by:
As a "newbie" to Javascript I need some help with my latest problem... I have a number of image files that have been pre-selected by the user for downloading. I'd like to be able to have the user click a button and have a directory browser pop-up window available for the user to select the directory into which the image files will be downloaded. I thought that this would be simple to find but... If this is possible I further need to...
5
5285
by: Baren | last post by:
Hi! I am using impersonate="true" to upload and download files from a network share. I have created common users on both the webserver and the file server. The user has permission to the files server folder. I am able to upload the files into the fileserver, but while downloading the same i am getting error "file doesn't exist" and the path it shows is localhost temporary internet files.
6
2714
by: Jatin | last post by:
Hey Guys I have a web application that allows users to download files. But the files are not hosted on the webserver. The files are stored on external servers and are referenced by a URL/URI. Since my application restricts the number of downloads for the file per user, i cannot show the user the URL/URI of the server hosting the file. Therefore i need to some how route the file via my webserver, and then use the Response to stream the...
14
4863
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it can be done using the designer but I intentionally don't want to use that. The one reason is that you cannot change the code generated by the designer. The other could be that you have more free hand and control to design your GUI. 2....
4
10248
by: Dale | last post by:
I am creating GIF images with transparent backgrounds on-the-fly for a web app and rendering them by using System.Drawing.Image.Save(Response.OutputStream, ImageType.GIF). I am confident that the transparency is working properly because if I save the created image to the local hard disk and then view it in a web page or an image editor, the transparency is correct. I can also view the transparency on-the-fly in a Windows.Forms...
1
1281
by: dr | last post by:
does anyone see what is wrong with my .gif download logic? no matter what image url i try it downloads a junk file that can't be opened in any paint program. System.Net.WebRequest myRequest = System.Net.WebRequest.Create(url); System.Net.WebResponse myResponse = myRequest.GetResponse(); System.IO.Stream imgStream = myResponse.GetResponseStream(); long len = myResponse.ContentLength; byte binarydata = new byte;
19
2435
by: active | last post by:
The ColorPalette class has no constructor so how does one use it? I define a variable by: Dim cp as ColorPalette but don't know how assign an object to the variable. Thanks in advance
5
1592
by: dp_pearce | last post by:
I have some code that takes data from an Access database and processes it into text files for another application. At the moment, I am using a number of loops that are pretty slow. I am not a hugely experienced python user so I would like to know if I am doing anything particularly wrong or that can be hugely improved through the use of another method. Currently, all of the values that are to be written to file are pulled from the...
1
2307
by: progman417 | last post by:
My Shareware program (or rather Commerical Program with a time limited demo) used to have sales of around $2,000 per month around 2002, but then I got busy at work and didn't have time to maintain it, so sales dwindled off to about $200 a month or less. I still get the odd sale now and again. Recently whilst looking for a job I've spent months updating the software and I believe it's better than the competition, but after 2 months zero...
0
9453
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10036
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.