温馨提示×

C#中如何实现WebBrowser控件的网页下载功能

c#
小樊
104
2024-08-12 05:07:33
栏目: 编程语言

在C#中,可以使用WebClient类来实现WebBrowser控件的网页下载功能。下面是一个简单的示例代码:

using System;
using System.Net;

class Program
{
    static void Main()
    {
        WebClient webClient = new WebClient();
        
        // 设置要下载的网页地址
        string url = "http://www.example.com";
        
        // 设置要保存的文件路径
        string filePath = "C:/example.html";
        
        // 下载网页
        webClient.DownloadFile(url, filePath);
        
        Console.WriteLine("网页下载完成!");
    }
}

在上面的代码中,首先创建了一个WebClient对象,然后设置要下载的网页地址和保存的文件路径,最后调用DownloadFile方法来下载网页。下载完成后,会在控制台输出"网页下载完成!"。

0