c# 使用 WebClient 下载文件并保存

标签 c#

我有下载文件的代码,它只是替换了它。

    WebClient webClient = new WebClient();
    {
          webClient.DownloadFile("http://test.png", "C:\PNG.png")
    } 

我只是想知道,是否可以下载文件,然后保存文件而不是替换旧文件(在上面的示例中,png.png)。

最佳答案

每次都创建一个唯一的名称。

WebClient webClient = new WebClient();
{
    webClient.DownloadFile("http://test.png", string.Format("C:\{0}.png", Guid.NewGuid().ToString()))
} 

关于c# 使用 WebClient 下载文件并保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33649294/

相关文章:

c# - WPF MVVM 为什么使用 ContentControl + DataTemplate View 而不是直接的 XAML 窗口 View ?

c# - 在 .NET 中获取文件类型

c# - 使用 MapHttpRoute 配置 WebAPI 路由时出错

c# - 在 Azure 上运行时的输出与在本地构建上运行时的输出不同

c# - 函数不会返回任何内容

c# - 如何计算linq中的重复项?

c# - 在构造函数之前设置字段或属性值

java - Android 声明类似于 RadioGroup 的 "for each"

C# - 访问 JsonSerializer 对象的值

c# - 在每个页面中使用 namespace 是否是一种不好的做法/降低性能或内存使用