您可以使用C#中的WebClient类来下载文件。以下是一个简单的示例代码,演示如何使用WebClient下载文件:
using System;using System.Net;class Program{ static void Main() { string url = "http://example.com/file.pdf"; string savePath = "C:\\Downloads\\file.pdf"; using (WebClient client = new WebClient()) { client.DownloadFile(url, savePath); Console.WriteLine("File downloaded to: " + savePath); } }}在这个示例中,我们首先创建一个WebClient实例,然后使用DownloadFile方法从指定的URL下载文件,并指定要保存的文件路径。最后,我们打印出文件下载的路径。
请确保您的应用程序有适当的权限来写入指定的文件路径。


