Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Sep 22, 2012 11:48 AM by Neodynamic
Member
2 Points
6 Posts
Sep 18, 2012 12:10 PM|LINK
Hi,
I have a webpage, which will generate the PDF on the fly.
Now i want to download that PDF document from C# Console Application using the parallel Technique.
But this program is not downloading the files properly; all the PDF files are 1 KB in size and corrupted.
The Progrma is Given Below.. Please some one help me to resolve this.
static void Main(string[] args) { Console.WriteLine("Enter the No Of thread..."); int _ThreadCount = int.Parse(Console.ReadLine()); string[] _listCasid = ConfigurationManager.AppSettings["ListofID"].ToString().Split(new string[] { ";"}, StringSplitOptions.RemoveEmptyEntries); Parallel.For(0, _ThreadCount, item => { using (WebClient webClient = new WebClient()) { String Uri=""; string file_name=""; Uri = "https://example.com?id=" + _listCasid[item].ToString(); file_name = @"D:\Temp\File_" + _listCasid[item].ToString() + ".pdf"; webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(delegate(object sender, AsyncCompletedEventArgs e) { Console.WriteLine(file_name + " Download Completed"); }); webClient.DownloadFileAsync(new Uri(Uri), file_name); } } ); Console.WriteLine("Press any key to quir from the program.."); Console.ReadKey(); }
Contributor
3732 Points
1275 Posts
Sep 22, 2012 08:03 AM|LINK
Plz give the url and let's try
Participant
1008 Points
289 Posts
Sep 22, 2012 11:48 AM|LINK
You are trying to get it from an HTTPS so maybe there's some certificate validation errors which are preventing you to get the files. Try adding the following code before webClient.DownloadFileCompleted
ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
srikanth_d
Member
2 Points
6 Posts
Not able to Downlod the PDF from webpage using WebClient
Sep 18, 2012 12:10 PM|LINK
Hi,
I have a webpage, which will generate the PDF on the fly.
Now i want to download that PDF document from C# Console Application using the parallel Technique.
But this program is not downloading the files properly; all the PDF files are 1 KB in size and corrupted.
The Progrma is Given Below.. Please some one help me to resolve this.
static void Main(string[] args) { Console.WriteLine("Enter the No Of thread..."); int _ThreadCount = int.Parse(Console.ReadLine()); string[] _listCasid = ConfigurationManager.AppSettings["ListofID"].ToString().Split(new string[] { ";"}, StringSplitOptions.RemoveEmptyEntries); Parallel.For(0, _ThreadCount, item => { using (WebClient webClient = new WebClient()) { String Uri=""; string file_name=""; Uri = "https://example.com?id=" + _listCasid[item].ToString(); file_name = @"D:\Temp\File_" + _listCasid[item].ToString() + ".pdf"; webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(delegate(object sender, AsyncCompletedEventArgs e) { Console.WriteLine(file_name + " Download Completed"); }); webClient.DownloadFileAsync(new Uri(Uri), file_name); } } ); Console.WriteLine("Press any key to quir from the program.."); Console.ReadKey(); }www.itdiligent.com
TimoYang
Contributor
3732 Points
1275 Posts
Re: Not able to Downlod the PDF from webpage using WebClient
Sep 22, 2012 08:03 AM|LINK
Plz give the url and let's try
Neodynamic
Participant
1008 Points
289 Posts
Re: Not able to Downlod the PDF from webpage using WebClient
Sep 22, 2012 11:48 AM|LINK
You are trying to get it from an HTTPS so maybe there's some certificate validation errors which are preventing you to get the files. Try adding the following code before webClient.DownloadFileCompleted
ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };