File processing in asp.net (2)

Source: Internet
Author: User
Tags readline
asp.net 1). The main ideas and steps in program design:

The program language used in this asp.net page is vb.net. The main function of the program is to open the specified file and display the file in ASCII form. Here are some of the main steps in programming:

i>. Read the objects used in the file--streamreader

In the System.IO defines a read the file object--streamreader, this program is through this object completes to the file the reading. It is then displayed in text form. Specifically as follows:

Dim Streamreaderobj as StreamReader
file_name = filename. Postedfile.filename
' read out a designated file and assign him to the StreamReader object
Todo
Filecont = Streamreaderobj. ReadLine ()
Response.Write (Filecont & "<br>")
Loop Until Filecont = ""
' Read the contents of the file one line at a time, and then stop until you read a line with an empty string.
Streamreaderobj. Close
' Close the StreamReader object after the read operation is complete


ii> the Form used in the program should be encoded as "Multipart/form-data" without his default encoding. Specifically as follows:

<form method = "Post" enctype = "multipart/form-data" runat = "server" >
</form >

2). The source code of the program:

<% @ Import Namespace = "System.IO"%>
<script language = "vb" runat = "server" >
Sub Sendbutton_click (sender as Object, E as EventArgs)
' Create a StreamReader object
Dim Streamreaderobj as StreamReader
Dim file_name as String
' Define a variable to hold the content read from the file
Dim Filecont as String
Streamreaderobj = File.OpenText (file_name)
Panel1.visible = False
' Read the contents of the file one line at a time, and then stop until you read a line with an empty string.
Todo
Filecont = Streamreaderobj. ReadLine ()
' Read files using the StreamReader object
Response.Write (Filecont & "<br>")
' Show file contents
Loop Until Filecont = ""

' Close the StreamReader object after the read operation is complete
Streamreaderobj. Close
Response.Write ("<br> above is the full contents of the & file_name &" File!) " )
End Sub
</script>
<asp:panel id = "Panel1" runat = "server" >
<form method = "Post" enctype = "multipart/form-data" runat = "server" >
<p> Welcome to read the file on the asp.net page </p
Please select File name: <input type = "file" id = "FileName" runat = "server"/> <BR
<asp:button id = "Write" Text = "Read file" OnClick = "Sendbutton_click" runat = "server"/>
</form >
</asp:panel >


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.