blah blah blah is here! blah blah » Close

up0down
link

I want to search a word from all the words that appear in all my webpages, and show the result of occurrence in a textBox, in the default.aspx page.
I want to get all the words that appear in my website in a string. Can it be done anyway?

last answered 2 years ago

1 answers

up0down
link

I just got an article from <b>Scott Mitchell</b> but it was in VB. If anyone kindly convert it into C# Probably what I wanted to do is there.....
<b>First Code:</b>
<%@ Import Namespace="System.Net" %>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
'STEP 1: Create a WebClient instance
Dim objWebClient as New WebClient()
'STEP 2: Call the DownloadedData method
Const strURL as String = "http://www.aspmessageboard.com/"
Dim aRequestedHTML() as Byte
aRequestedHTML = objWebClient.DownloadData(strURL)
'STEP 3: Convert the Byte array into a String
Dim objUTF8 as New UTF8Encoding()
Dim strRequestedHTML as String
strRequestedHTML = objUTF8.GetString(aRequestedHTML)
'WE'RE DONE! - display the string
lblHTMLOutput.Text = strRequestedHTML
End Sub
</script>
<html>
<body>
<h1>Screen Scrape of www.aspmessageboard.com</h1>
<p>
<asp:label id="lblHTMLOutput" runat="server" />
</body>
</html>
<b>Second Code:</b>
<%@ Import Namespace="System.Net" %>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
'STEP 1: Create a WebClient instance
Dim objWebClient as New WebClient()
'STEP 2 and 3
Const strURL as String = "http://www.aspmessageboard.com/"
Dim objUTF8 as New UTF8Encoding()
lblHTMLOutput.Text = objUTF8.GetString(objWebClient.DownloadData(strURL))
End Sub
</script>
<html>
<body>
<h1>Screen Scrape of www.aspmessageboard.com</h1>
<p>
<asp:label id="lblHTMLOutput" runat="server" />
</body>
</html>

up0down
link

OK, here's my attempt (untested):
<b>First Code:</b>
<%@ Import Namespace="System.Net" %>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
// STEP 1: Create a WebClient instance
WebClient objWebClient = new WebClient();
// STEP 2: Call the DownloadedData method
const string strURL = "http://www.aspmessageboard.com/";
byte[] aRequestedHTML = objWebClient.DownloadData(strURL);
// STEP 3: Convert the byte array into a string
UTF8Encoding objUTF8 = new UTF8Encoding();
string strRequestedHTML = objUTF8.GetString(aRequestedHTML);
// WE'RE DONE! - display the string
lblHTMLOutput.Text = strRequestedHTML;
}
</script>
<html>
<body>
<h1>Screen Scrape of www.aspmessageboard.com</h1>
<p>
<asp:label id="lblHTMLOutput" runat="server" />
</body>
</html>
<b>Second Code:</b>
<%@ Import Namespace="System.Net" %>
<script language="C#" runat="server">
void Page_Load(sender as Object, e as EventArgs)
{
// STEP 1: Create a WebClient instance
WebClient objWebClient = new WebClient();
// STEP 2 and 3
const string strURL = "http://www.aspmessageboard.com/";
UTF8Encoding objUTF8 = new UTF8Encoding();
lblHTMLOutput.Text = objUTF8.GetString(objWebClient.DownloadData(strURL));
}
</script>
<html>
<body>
<h1>Screen Scrape of www.aspmessageboard.com</h1>
<p>
<asp:label id="lblHTMLOutput" runat="server" />
</body>
</html>

up0down
link

Many many thanks vulpes. I tried the first one in a local file system aspx page, and it's working fine. The content of any page can be taken into the string.
Will you kindly check the second code eventhandler part?
Again thanks. and regards to Scott Mitchell .

up0down
link

Doh, in the second lot of code I've forgotten to change the parameters to C# notation. So this line:
void Page_Load(sender as Object, e as EventArgs)
should be:
void Page_Load(Object sender, EventArgs e)

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback