473,473 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dowload File

Hi,
I have problem with downloading a file using WebRequest and
HttpWebResponse.
Inorder to download this file i need to call to url that tells to
prepare the file for download,
and then i call to another url that downloads the file.
I have a problem with that because:

1. i do not know when the server finished the preparetion.
2.i checked the HttpStatusCode but he doen't changes
(myresponse.StatusCode).

the problem causes the application to download only a part of the file
and that because the server hasn't prepared the file yet.
if i give him Thread.Sleep(100000) i do get the full file, but the file
can be 100Mb and 10sec won't help.

the code is:
//Preparing the file todownload...
//---------------------------------------------------------------------------------------------------------
HttpWebRequest webRequest3 = WebRequest.Create(d1) as
HttpWebRequest;
webRequest3.KeepAlive = true;
webRequest3.Headers.Add("Keep-Alive", "300");
webRequest3.Headers.Add("Accept","text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
webRequest3.Headers.Add("Accept-Language",
"en-us,en;q=0.5");
webRequest3.Headers.Add("Accept-Encoding", "gzip,deflate");
webRequest3.Headers.Add("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");

webRequest3.CookieContainer = cookies;
HttpWebResponse myResponse3 =
(HttpWebResponse)webRequest3.GetResponse();

Thread.Sleep(10000);
Stream ReceiveStream3 = myResponse3.GetResponseStream();

//-----------------------------------------------------------------------------------

//Downloading ....
//--------------------------------------------------------------------------------------
Console.WriteLine("Connecting to download link...");
HttpWebRequest webRequest2 = WebRequest.Create(re) as
HttpWebRequest;
webRequest2.ContentType =
"application/x-www-form-urlencoded";
webRequest2.KeepAlive = true;
webRequest2.CookieContainer = cookies;
HttpWebResponse myResponse2 =
(HttpWebResponse)webRequest2.GetResponse();
Stream ReceiveStream2 = myResponse2.GetResponseStream();
Console.WriteLine("Downloading...");

Common.SaveStreamToFile(@"C:\scrapingtest\file.csv ",
ReceiveStream2);
Console.WriteLine("Done Downloading");

Thanks, Rony

Sep 19 '06 #1
1 1266
Thus wrote rony_16,
Hi,
I have problem with downloading a file using WebRequest and
HttpWebResponse.
Inorder to download this file i need to call to url that tells to
prepare the file for download,
and then i call to another url that downloads the file.
I have a problem with that because:
1. i do not know when the server finished the preparetion. 2.i checked
the HttpStatusCode but he doen't changes (myresponse.StatusCode).
HTTP is all about exchanging requests and responses. How do you expect the
server to signal a "ready" state? Is there any application specific protocol
layered on top?
the problem causes the application to download only a part of the file
and that because the server hasn't prepared the file yet.
if i give him Thread.Sleep(100000) i do get the full file, but the
file
can be 100Mb and 10sec won't help.
You don't have to wait explicitly. GetResponseStream() will block until either
the entire response has been read or times out.
Are you sure the method Common.SaveStreamToFile() is implemented correctly?

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Sep 20 '06 #2

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

Similar topics

13
by: dvsbis | last post by:
does anybody have example of file download using java script thanks dave dvs_bis@sbcglobal.net
3
by: Jerry Camel | last post by:
How do you tell the client how large the file that's being downloaded is? I've seen web sites where the download dialog shows a progress meter. I'm assuming that the server is sending the file...
2
by: marcos | last post by:
sorry, but my english are very bad... how lto dowload visual basic 6.0 from internet?
4
by: Albano Alves | last post by:
Hi! How can I force the file download, for example a .doc? I don't want to open with IE. Thanks. Albano Alves
2
by: comick | last post by:
Hello all, i have a asp.net c# web app 2.0 I have a pdf generation with a third part sw, but i cant download pdf in a new window, from a folder inside my web site. The code i try to use is...
6
by: rony_16 | last post by:
Hi, I have problem with downloading a file using WebRequest and HttpWebResponse. Inorder to download this file i need to call to url that tells to prepare the file for download, and then i call...
1
by: nkamalnath | last post by:
hi, How to dowload a file using javascript.
3
by: Ken Ross | last post by:
Hi all, I have an asp.net 2.0 page that allows users to download a file after clicking the "download now" button. I'm using very similar code to what I've seen on a number of other posts: ...
2
by: nbt725 | last post by:
Dear Sir, Hello ! I want to write a script to allow downloading a file from server, which first asks for the path to store the file and then downloads to user's local machine. Please guide me....
0
by: namrataa | last post by:
how do u download/upload a file in wpf where the data is stored in the database in the binary format. how to link asp.net pages in wpf. please help....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
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...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.