473,765 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
+ 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.Sta tusCode).

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(10 0000) 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.Crea te(d1) as
HttpWebRequest;
webRequest3.Kee pAlive = true;
webRequest3.Hea ders.Add("Keep-Alive", "300");
webRequest3.Hea ders.Add("Accep t","text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,ima ge/png,*/*;q=0.5");
webRequest3.Hea ders.Add("Accep t-Language",
"en-us,en;q=0.5");
webRequest3.Hea ders.Add("Accep t-Encoding", "gzip,deflate") ;
webRequest3.Hea ders.Add("Accep t-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7 ");

webRequest3.Coo kieContainer = cookies;
HttpWebResponse myResponse3 =
(HttpWebRespons e)webRequest3.G etResponse();

Thread.Sleep(10 000);
Stream ReceiveStream3 = myResponse3.Get ResponseStream( );

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

//Downloading ....
//--------------------------------------------------------------------------------------
Console.WriteLi ne("Connecting to download link...");
HttpWebRequest webRequest2 = WebRequest.Crea te(re) as
HttpWebRequest;
webRequest2.Con tentType =
"applicatio n/x-www-form-urlencoded";
webRequest2.Kee pAlive = true;
webRequest2.Coo kieContainer = cookies;
HttpWebResponse myResponse2 =
(HttpWebRespons e)webRequest2.G etResponse();
Stream ReceiveStream2 = myResponse2.Get ResponseStream( );
Console.WriteLi ne("Downloading ...");

Common.SaveStre amToFile(@"C:\s crapingtest\fil e.csv",
ReceiveStream2) ;
Console.WriteLi ne("Done Downloading");

Thanks, Rony

Sep 19 '06 #1
0 1886

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

Similar topics

13
1913
by: dvsbis | last post by:
does anybody have example of file download using java script thanks dave dvs_bis@sbcglobal.net
3
1143
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 size prior to download. Maybe in the "Content-Disposition" header? Thanks. Jerry
2
2516
by: marcos | last post by:
sorry, but my english are very bad... how lto dowload visual basic 6.0 from internet?
4
1178
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
1499
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 this: ...pdf Generation.. Response.Clear(); Response.ContentType = "application/pdf";
6
414
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 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
1
1790
by: nkamalnath | last post by:
hi, How to dowload a file using javascript.
3
1269
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: Response.Clear() Response.ContentType = "application/octet-stream" Response.TransmitFile(fullFilePath) Response.End()
2
1763
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. Thanks & Regards, Naimesh Trivedi
0
777
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
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9959
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,...
1
7379
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
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
5277
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
3926
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
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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.