Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Feb 2011
    Posts
    18
    Thanks
    6
    Thanked 0 Times in 0 Posts

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

    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?

    Code:
    <%@ 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
    if(Page.IsPostBack)
    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
    sr.Close();
    }
    return strResult;
    }
    
    </script>
    <HTML>
    <HEAD>
    <title>Page Scrape in C# - CSharpFriends</title>
    </HEAD>
    <body>
    <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>
    <br>
    <asp:Literal ID="litHTMLfromScrapedPage" Runat="server" />
    </form>
    </body>
    </HTML>



    this is what I have at the top of my .aspx file already for the language:
    Code:
    <%@ 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">
    Last edited by tightendutah; 02-09-2011 at 06:30 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •