Not able to Downlod the PDF from webpage using WebClient

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin-bottom:12.0pt <span style="font-size:9pt; font-family:Verdana,sans-serif Hi,
<p style="margin:0in 0in 12pt; line-height:13.5pt <span style="font-size:9pt; font-family:Verdana,sans-serif I have a webpage, which will generate the PDF on the fly.
<p style="margin:0in 0in 12pt; line-height:13.5pt <span style="font-size:9pt; font-family:Verdana,sans-serif Now i want to download that PDF document from C# Console Application using the parallel Technique.
<p style="margin:0in 0in 12pt; line-height:13.5pt <span style="font-size:9pt; font-family:Verdana,sans-serif 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.
<pre class="prettyprint" style=" 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:TempFile_" + _listCasid[item].ToString() + ".pdf";
webClient.HeadOnly = false;
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();
}[/code]
<br/>

<
Kanth <br/>
www.itdiligent.com itdiligent
<br/>

View the full article
 
Back
Top