为什么不在C#表单app中完全下载 [英] Why fil not downloads fully in C# form app

查看:65
本文介绍了为什么不在C#表单app中完全下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。我是C#的新手。实际上我是编程新手。我写了一个下载程序。但是当文件下载得到损坏时,
得到了corrupted.any format.exe,zip,mp3,it无所谓.i下载了测试代码,没有任何内容..同样的......那么你能帮助我得到什么意思吗?请帮忙...



所以这是代码

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

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() + "%";
}

推荐答案

根据您的代码,您永远不会开始下载任何内容。实际上你正在创建一个空文件...

见这里 http://msdn.microsoft.com/en-us/library/ez801hhe(v = vs.110).aspx [ ^ ]
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[^]


请查看以下链接解决方案



http://stackoverflow.com / questions / 16067035 / file-not-downloaded-complete [ ^ ]



http://stackoverflow.com/questions/11687416/file-is-not-downloading-completely [ ^ ]
Please check following links for solution

http://stackoverflow.com/questions/16067035/file-not-downloaded-completely[^]

http://stackoverflow.com/questions/11687416/file-is-not-downloading-completely[^]


这篇关于为什么不在C#表单app中完全下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆