473,396 Members | 1,816 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,396 software developers and data experts.

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
0 1845

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
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,...

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.