Last Updated: February 25, 2016
·
3.701K
· codehill

Get the Title of a Webpage in Windows Forms Using C#

Here's a simple way to get the title of a webpage in C# using:

static string GetPageTitle(string link)
{
    try
    {
        WebClient wc = new WebClient();
        string html = wc.DownloadString(link);

        Regex x = new Regex("<title>(.*)</title>");
        MatchCollection m = x.Matches(html);

        if (m.Count > 0)
        {
            return m[0].Value.Replace("<title>", "").Replace("</title>", "");
        }
        else
            return "";
    }
    catch (Exception ex)
    {
        Console.WriteLine("Could not connect. Error:" + ex.Message);
        return "";
    }
}

Link: http://codehill.com/2013/11/get-title-webpage-windows-forms/