Hi all,
I'm storing a set of "<a href" tags in a list. Now i want to check all these links are valid or not? i.e, the list contains any broken links or not.
This is the code.....
the code will allow user to enter the url and it will render all the html code back
and display only the href tags. Now i want to check the validity of all these links
and display the result.... i.e all the links are not dead.....
-
// make an object of the WebClient class
-
WebClient objWebClient = new WebClient();
-
// gets the HTML from the url written in the textbox
-
aRequestHTML = objWebClient.DownloadData(TextBox1.Text);
-
// creates UTf8 encoding object
-
UTF8Encoding utf8 = new UTF8Encoding();
-
// gets the UTF8 encoding of all the html we got in aRequestHTML
-
myString = utf8.GetString(aRequestHTML);
-
-
-
ArrayList list = new ArrayList();
-
int curindex = 0;
-
int index = 0;
-
do
-
{
-
index = myString.IndexOf("<a href=", curindex);
-
if (index==-1) {break;}
-
curindex = myString.IndexOf(">", index);
-
string ancordata = myString.Substring(index, curindex - index);
-
if (ancordata.ToLower().IndexOf("javascript") < 0)
-
{
-
list.Add(ancordata);
-
}
-
}
-
while (index != -1);
-
GridView1.DataSource = list;
-
//// binds the databind
-
GridView1.DataBind();
-