Home arrow ASP.NET arrow Page 5 - Reading a Delimited File Using ASP.Net and VB.Net

Reading a Delimited File Using ASP.Net and VB.Net

New to .NET? Wondering how to split contents using a delimiter? No problem, this latest article from Ajaykumar shows you just how easy reading the contents of a delimited file can be.

Author Info:
By: G Ajaykumar
Rating: 4 stars4 stars4 stars4 stars4 stars / 224
October 15, 2003
  1. · Reading a Delimited File Using ASP.Net and VB.Net
  2. · Usage
  3. · Example Code
  4. · Example Code, Cont'd
  5. · Code Explanation
  6. · Output

print this article

Reading a Delimited File Using ASP.Net and VB.Net - Code Explanation
(Page 5 of 6 )

To test this script you will be creating two files:  One .aspx file and the other, a .txt file.

  1. Open your notepad
  2. Copy the following complete code

 Beginning of script Reading a delimited text file written by G.Ajaykumar<

<%@Import Namespace="System.IO"%>
<script language="vb" runat="server">
Sub page_load(Sender As Object,e As EventArgs)
   Dim filetoread as string
   dim filestream as StreamReader
   filestream = File.Opentext(filetoread)
   Dim readcontents as String
   readcontents = fileStream.ReadToEnd()
   Dim textdelimiter as String
   textdelimiter = ","
   Dim splitout = Split(readcontents,textdelimiter)
      lblplaintext.text = readcontents & "<br>"
    dim i as integer
    for i=0 to Ubound(splitout)
  lblsplittext.Text &= "<b>Split </b>" & i+1 & ")   " & splitout(i)& "<br>"
End Sub
<asp:label align="center" ForeColor="Maroon" Font-Names="Arial" BackColor="LemonChiffon" BorderColor="#0000C0" runat="server" id="lbldisplay" Font-Name="Verdana" text="Reading a delimited text file using ASP.NET/VB.NET coded by G.Ajaykumar" /><br />
<br /><br /><b>Plain Output</b><br />
<asp:label runat="server" id="lblplaintext" Font-Name="Verdana" /><br />
<b>Split Output</b><br />
<asp:label runat="server" id="lblsplittext" Font-Name="Verdana" />
<%-- End of script--%>

Save the file as readdelimit.aspx.

Now, create a textfile named readtest.txt and copy the following text to that file and save it:

History of the world, is the history of few men who had faith in themselves, that faith calls out the divinity, with in, you can do anything you fail only when you do not strive sufficiently to manifest the infinite power, if you have faith in all the three hundred and thirty millions, of your mythological gods and in all the gods which foreign has now and gain faith, in yourselfs,what ever you hink that you will be if you think weak weak, you will be,if you think yourselves strong strong you will ,be free and hope for nothing from any one.

readdelimit.aspx is the source file and readtest.txt is the delimited text file.  Dump these files to your wwwroot directory and run readlimit.aspx.  Thatís it!

Next: Output >>

blog comments powered by Disqus

- How Caching Means More Ca-ching, Part 2
- How Caching Means More Ca-ching, Part 1
- Reading a Delimited File Using ASP.Net and V...
- What is .Net and Where is ASP.NET?
- An Object Driven Interface with .Net
- Create Your Own Guestbook In ASP.NET
- HTTP File Download Without User Interaction ...
- Dynamically Using Methods in ASP.NET
- Changing the Page Size Interactively in a Da...
- XML Serialization in ASP.NET
- Using Objects in ASP.NET: Part 1/2
- IE Web Controls in VB.NET
- Class Frameworks in VB .NET
- Cryptographic Objects in C#: Part 1
- Sample Chapter: Pure ASP.Net

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials