C#,通过网络浏览器下载

时间:2020-11-07 12:50:39

标签: c# download

在使用自己的Webbrowser下载时,我需要一些帮助:

我在安装时遇到了麻烦。如果我开始下载zip之类的文件,旧的边缘浏览器会崩溃,但是如何破坏它并从浏览器安装呢?

使用代码:

 `if (e.Url.Segments[e.Url.Segments.Length - 1].EndsWith(".pdf"))
        {
            string filepath = null;

            saveFileDialog1.FileName = e.Url.Segments[e.Url.Segments.Length - 1];
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                filepath = saveFileDialog1.FileName;
                WebClient client = new WebClient();
                client.DownloadFileAsync(e.Url, filepath);
            }
        }
        else if (e.Url.Segments[e.Url.Segments.Length - 1].EndsWith(".exe"))
        {
            string filepath = null;

            saveFileDialog1.FileName = e.Url.Segments[e.Url.Segments.Length - 1];
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                filepath = saveFileDialog1.FileName;
                WebClient client = new WebClient();
                client.DownloadFileAsync(e.Url, filepath);
            }
        }
        else if (e.Url.Segments[e.Url.Segments.Length - 1].EndsWith(".rar"))
        {
            string filepath = null;

            saveFileDialog1.FileName = e.Url.Segments[e.Url.Segments.Length - 1];
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                filepath = saveFileDialog1.FileName;
                WebClient client = new WebClient();
                client.DownloadFileAsync(e.Url, filepath);
            }
        }
        else if (e.Url.Segments[e.Url.Segments.Length - 1].EndsWith(".zip"))
        {
            string filepath = null;

            saveFileDialog1.FileName = e.Url.Segments[e.Url.Segments.Length - 1];
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                filepath = saveFileDialog1.FileName;
                WebClient client = new WebClient();
                client.DownloadFileAsync(e.Url, filepath);
            }
        }´

0 个答案:

没有答案