C# 下载远程http文件到本地

来源:互联网 发布:linux黑客大曝光 编辑:程序博客网 时间:2024/05/23 00:11
 System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
                dialog.Description = "请选择保存路径";
                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string url = q.IpAddress + path;
                    try
                    {
                        using (var client = new System.Net.WebClient())
                        {
                            client.DownloadFile(url, dialog.SelectedPath + "\\" + System.IO.Path.GetFileName(path));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "下载异常");
                        return;
                    }
原创粉丝点击