Click here to Skip to main content
15,038,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Lets say I have a windows form application programmed with c#. I want to know how can I connect this application to a website? For example how can I get the <title> of any website and display it on my application?
Posted
Comments
[no name] 1-Nov-12 6:55am
   
Connecting to a website is one thing and getting "<"title">" of any website is another one.
Usually you can make a connection to a website by its services.

try HtmlAgilityPack
it will help you..
don't forgot to add HtmlAgilityPack.dll in your project.
   
Try this:
C#
 using System.Xml;
  using System.Xml.XPath;
  using System.Xml.Linq;
  using System.Net;
/*...........................*/

  HttpWebRequest myReq = ( HttpWebRequest )WebRequest.Create( "http://www.contoso.com/" );
  myReq.AllowAutoRedirect = true;
  myReq.MaximumAutomaticRedirections = 5;
  XNode result;
  using( var responseStream = myReq.GetResponse( ).GetResponseStream( ) ) {
    result = XElement.Load( responseStream );
  }

  var title = result.XPathSelectElement( "//title" ).Value;
   
v2
Comments
missak boyajian 29-Oct-12 9:19am
   
Hey. It's just working for the www.contoso.com. I tried another websites it didn't work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900