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/
Written by Amgad Suliman
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#C#
Authors
Related Tags
#c#
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#