1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

File Handling! Reading Text File!

Discussion in 'C#' started by vincent85, Aug 26, 2005.

  1. #1
    Code (ASP):
    1. <%@Import Namespace="System.IO"%>
    2. <script language="vb" runat="server">
    3. Sub page_load(Sender As Object,e As EventArgs)
    4.    Dim filetoread as string
    5.    filetoread=server.mappath("Output.txt")
    6.    dim filestream as StreamReader
    7.    filestream = File.Opentext(filetoread)
    8.    Dim read as String=fileStream.ReadToEnd()
    9.    dim str1, s as string
    10.    dim i,k as integer
    11.     dim str1, str2(), s as string
    12.     dim i,k as integer
    13.         for k=0 to (read.count)-1
    14.             str1=read.item(k)
    15.             str2=str1.split("~")
    16.  
    17.             dim r As New TableRow()
    18.             dim c11 As New TableCell()
    19.             dim chkbox11 as new checkbox
    20.             c11.Controls.Add(chkbox11)
    21.             r.Cells.Add(c11)
    22.             for i=0 to 5
    23.             dim c As New TableCell()
    24.             c.Controls.Add(New LiteralContro(str2(i)))
    25.             r.Cells.Add(c)
    26.             next
    27.             table.Rows.Add(r)
    28.         next
    29.  
    30. end sub
    31. </script>
    32. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    33. <html>
    34. <head>
    35. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    36. <title>Contact Us</title>
    37. </head>
    38. <body>
    39. <p align="center">
    40.   <input name="imageField" type="image" src="image/bimicologo.jpg" >
    41. </p>
    42. <h2 align="center"><strong></strong></h2>
    43. <hr>
    44. <form runat="server">
    45. <table border="0" width="100%">
    46.     <tr>
    47.         <td width="15%" valign="top" rowspan="3"><a href="home_page.aspx">Home Page</a></br>
    48.             <b><a href="active_message.aspx">Active Message</a></b></br>
    49.             <a href="search.aspx">Search</a></br>  
    50.             <a href="contact_us.aspx">Contact Us</a>
    51.         </td>
    52.         <td width="100%">
    53.             <h4>Customer Messages</h4>
    54.             <asp:label id="submit_msg" runat="server"/>
    55.             <asp:table id="table" runat="server" width="100%" border="1">
    56.                 <asp:TableRow>
    57.                     <asp:TableheaderCell width="6%" halign="center">Remove</asp:TableheaderCell>
    58.                     <asp:TableheaderCell width="15%">Urgency Level</asp:TableheaderCell>
    59.                     <asp:TableheaderCell width="10%">Name</asp:TableheaderCell>
    60.                     <asp:TableheaderCell width="15%">e-mail</asp:TableheaderCell>
    61.                     <asp:TableheaderCell width="10%">Day Phone</asp:TableheaderCell>
    62.                     <asp:TableheaderCell width="10%">Mobile</asp:TableheaderCell>
    63.                     <asp:TableheaderCell width="50%">Message</asp:TableheaderCell>
    64.                 </asp:TableRow>
    65.             </asp:table>
    66.         </td>
    67.     </tr>
    68.     <tr>
    69.         <td align="center"><asp:button id="btnremove" runat="server" text="Remove message" /></td>
    70.     </tr>
    71. </table>
    72. </form>
    73. </body>
    74. </html>
    All i want to do is read the text file , split it , and display it in the Web page!
    However , i have some trouble with it , can any one help me plz!
     
    vincent85, Aug 26, 2005 IP
  2. heyman

    heyman Peon

    Messages:
    70
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this code to read the file line by line:

    Code (ASP):
    1.  Dim filetoread as string
    2.    filetoread=server.mappath("Output.txt")
    3. Dim sr as New StreamReader(filetoread )
    4.  
    5. Dim line as String = sr.ReadLine()
    6. Do While Not line is Nothing
    7. Response.Write(line & "<br>")
    8. line = sr.ReadLine()
    9. Loop
     
    heyman, Aug 26, 2005 IP
  3. vincent85

    vincent85 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Error: Index was Outside of the Bounds of the Array.

    Please take a look at my attachment , they will explaint what i want to do! thank!
     

    Attached Files:

    vincent85, Aug 26, 2005 IP