c#文件下载

public static string downzip(string url,string sname)
{
try
{
WebClient client = new WebClient();

string URLAddress = url;

string receivePath = System.Windows.Forms.Application.StartupPath + "/temp/" + sname + "/";
if (!Directory.Exists(receivePath))
{
Directory.CreateDirectory(receivePath);
}

client.DownloadFile(URLAddress, receivePath + System.IO.Path.GetFileName(URLAddress));
return receivePath + System.IO.Path.GetFileName(URLAddress);
}
catch (Exception ex)
{
NLogger.Error(sname+"--"+ url + "--下载失败--" +ex.ToString());
return null;
}
}

原文地址:https://www.cnblogs.com/lyl6796910/p/8182703.html