winfrom实现下载文件
string url = "http://123.123.123.123/Image/123.docx";
string remoteUri = System.IO.Path.GetDirectoryName(url);
string fileName = System.IO.Path.GetFileName(url);
string myStringWebResource = null;
WebClient myWebClient = new WebClient();
myStringWebResource = url;
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择下载路径";
string foldPath = "";
if (dialog.ShowDialog() == DialogResult.OK)
{
foldPath = dialog.SelectedPath;
}
if (string.IsNullOrEmpty(foldPath))
{
MessageBox.Show("请选择下载路径");
return;
}
myWebClient.DownloadFile(myStringWebResource, foldPath + fileName );
string fullfile = foldPath + fileName;
if (File.Exists(fullfile))//判断文件是否存在
{
MessageBox.Show("下载成功");
}
else
{
MessageBox.Show("下载成功");
}