View Full Version : Don't know how to use the C# code I found in ASP.net

02-09-2011, 07:23 PM
So I found some code to help accomplish what I want to do, I just don't know how to use it. I'm using Microsoft Visual Web Developer 2010 Express. The way I've been designing my website so far is by using an aspx file with all my javascript at the top and the html coding after it. I know how to use the html code, I just don't have any idea where to start with the c#. Do I have to put it in a seperate file or a special c# file?

<%@ Page language="c#"%>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<script runat="server" lang="c#">

private void Page_Load(object sender, System.EventArgs e)
//Retrieve URL from user input box
litHTMLfromScrapedPage.Text = GetHtmlPage( tbURL.Text );
public String GetHtmlPage(string strURL)
// the html retrieved from the page
String strResult;
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
// the using keyword will automatically dispose the object
// once complete
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()))
strResult = sr.ReadToEnd();
// Close and clean up the StreamReader
return strResult;

<title>Page Scrape in C# - CSharpFriends</title>
<form runat="server">
<p>Enter the URL to the page you want to scrape (include the http://)</p> <asp:TextBox ID="tbURL" Runat="server" /><asp:Button ID="btnSumbit" Text="Go!" Runat="server" /> <br>
<asp:Literal ID="litHTMLfromScrapedPage" Runat="server" />

this is what I have at the top of my .aspx file already for the language:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="FATP.aspx.vb" Inherits="FATP"
Debug="true" %>
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">