Find Whether the String is Present in a Particular WebPage(URL) or Not
Use the following Method to achieve this:
Note: You have to pass the URL address and the string variable to this method...
private bool SearchPage(string URL, string StrToLocate) { StreamReader SR; WebResponse Resp ; WebRequest MyWebRequest; string PageStr; MyWebRequest = WebRequest.Create(URL) ; MyWebRequest.Timeout = 10000 ; try { Resp = MyWebRequest.GetResponse() ; SR = new StreamReader(Resp.GetResponseStream()) ; PageStr = SR.ReadToEnd() ; SR.Close() ; PageStr = PageStr.ToUpper(); if ( PageStr.IndexOf(StrToLocate.ToUpper(), 0, PageStr.Length) != -1 ) return true; else return false; } catch ( WebException wex ) { if (wex.Status == WebExceptionStatus.Timeout) Response.Write("The request has timed out!") ; else Response.Write("There was some exception: " + wex.Message) ; return false; } }
No comments:
Post a Comment
Thank You for Your Comments. We will get back to you soon.