Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi.I am new at C#.Actually i am new at programming.I wrote a downloader program.But
when file downloads its gets corrupted.any format.exe, zip, mp3, it does not matter .i downloaded tested codes for it and nothing..its the same..so can you help me to get what is the point ?please help...

so this is code
C#
private void pictureBox2_Click(object sender, EventArgs e)
{
    FolderBrowserDialog Save = new FolderBrowserDialog();//Declaring the folder browsing dialog
    Save.RootFolder = Environment.SpecialFolder.Desktop;//setting to desktop
    if (Save.ShowDialog() == DialogResult.OK)//An if statement to to show the path in textbox
    {
        string Text = textBox1.Text.ToString();//formatting to string
        string[] arry = Text.Split('/');//splitting /
        string dad = arry[arry.Length - 1];
        ad = dad.Remove(dad.Length - 5);
        label5.Text = dad;
        path = String.Format("{0}//{1}",Save.SelectedPath,ad);
        WebClient wb = new WebClient();
      
        wb.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wb_DownloadProgressChanged);
        wb.DownloadFileCompleted += new AsyncCompletedEventHandler(wb_DownloadFileCompleted);
        wb.DownloadFileAsync(new Uri(textBox1.Text), path);
       
        timer1.Start();        
    }      
}

void wb_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
        timer1.Stop();
    
        DialogResult dr = MessageBox.Show("Yukl?m? bitmisdir! Icra olunsun?", "Bitdi!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        if (dr == DialogResult.Yes)
        {
            progressBar1.Value = 0;
            Process.Start(path);
        } 
}

void wb_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
    progressBar1.Value = e.ProgressPercentage;
    label7.Text = e.BytesReceived.ToString() + " bayt";
    label6.Text = e.TotalBytesToReceive.ToString() + "bayt";
    label8.Text = e.ProgressPercentage.ToString() + "%";
}
Posted
v3
Comments
Kornfeld Eliyahu Peter 13-Jan-14 5:01am    
Can you share your code with us - it's hard to say too much without...
Member 10492763 13-Jan-14 5:04am    
private void pictureBox2_Click(object sender, EventArgs e)
{
FolderBrowserDialog Save = new FolderBrowserDialog();//Declaring the folder browsing dialog
Save.RootFolder = Environment.SpecialFolder.Desktop;//setting to desktop
if (Save.ShowDialog() == DialogResult.OK)//An if statement to to show the path in textbox
{
string Text = textBox1.Text.ToString();//formatting to string
string[] arry = Text.Split('/');//splitting /
string dad = arry[arry.Length - 1];
ad = dad.Remove(dad.Length - 5);
label5.Text = dad;
path = String.Format("{0}//{1}",Save.SelectedPath,ad);
WebClient wb = new WebClient();




wb.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wb_DownloadProgressChanged);
wb.DownloadFileCompleted += new AsyncCompletedEventHandler(wb_DownloadFileCompleted);
wb.DownloadFileAsync(new Uri(textBox1.Text), path);

timer1.Start();

}


}

void wb_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{

timer1.Stop();

DialogResult dr = MessageBox.Show("Yukl?m? bitmisdir! Icra olunsun?", "Bitdi!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
progressBar1.Value = 0;
Process.Start(path);
}

}

void wb_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
label7.Text = e.BytesReceived.ToString() + " bayt";
label6.Text = e.TotalBytesToReceive.ToString() + "bayt";
label8.Text = e.ProgressPercentage.ToString() + "%";
}
Can you please show your codes?

According to your code, you never start to download nothing. Practically you are creating an empty file...
See here http://msdn.microsoft.com/en-us/library/ez801hhe(v=vs.110).aspx[^]
 
Share this answer
 
 
Share this answer
 
Comments
Member 10492763 13-Jan-14 5:25am    
what is wrong in my code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900