Reading a Delimited File Using ASP.NET and VB.NET
page 4 of 4
by G Ajaykumar
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 41023/ 48

Test Script

To test this script you will be creating two file one .aspx file and the other .txt file

 

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

 

<%--

 Beginning of script Reading a delimited text file written by G.Ajaykumar<ajaykumar_g AT hotmail.com>--%>

 

<%@Import Namespace="System.IO"%>

<script language="vb" runat="server">

Sub page_load(Sender As Object,e As EventArgs)

                                    Dim filetoread as string

                                    filetoread=server.mappath("readtest.txt")

                                    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>"

    next

   filestream.Close()                

End Sub

</script>

<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 readdemilit.apx

 

  1. 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.

 

readlimit.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!

 

Your output should look like the following

 

Plain Output
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.

Delimited Output
Split 1) History of the world
Split 2) is the history of few men who had faith in themselves
Split 3) that faith calls out the divinity
Split 4) with in
Split 5) you can do anything you fail only when you do not strive sufficiently to manifest the infinite power
Split 6) if you have faith in all the three hundred and thirty millions
Split 7) of your mythological gods and in all the gods which foreign has now and gain faith
Split 8) in yourselfs
Split 9) what ever you hink that you will be if you think weak weak
Split 10) you will be
Split 11) if you think yourselves strong strong you will
Split 12) be free and hope for nothing from any one.


View Entire Article

User Comments

Title: Life Saver and excellent article   
Name: Muzaffar Sadiq
Date: 2007-12-14 7:34:01 AM
Comment:
I really appreciate if you could tell me that after reading data from a delimited file, how I can put data (value) in SharePoint list?

Thank you
Title: Excellent article!!   
Name: Cilina
Date: 2007-12-10 8:52:57 PM
Comment:
This is an excellent article. It works out so pretty :))))))))
Title: Localisation Manager   
Name: JaimeHy
Date: 2007-07-20 3:48:36 PM
Comment:
Nice article. Detailed enough explanation.

Very complete.

Thanks!
Title: Check out this library   
Name: Netra
Date: 2007-02-25 3:30:50 PM
Comment:
forgot to post URL!

http://vishalseth.com/blog/vishaltextfileutils/

there it is.

this library does everything with delimited files. it can convert to and from any format, open, write, read, reorder columns. Very usefull.
Title: Check out this library   
Name: Netra
Date: 2007-02-25 3:29:37 PM
Comment:
this library does everything with delimited files. it can convert to and from any format, open, write, read, reorder columns. Very usefull.
Title: very good   
Name: a visitor
Date: 2006-12-20 10:08:11 AM
Comment:
a same copy can be found out also at the link below ...
http://www.devarticles.com/c/a/ASP.NET/Reading-a-Delimited-File-Using-ASP.Net-and-VB.Net/
Title: how to read a delimited text file using asp.net   
Name: Dung vu
Date: 2006-11-28 12:09:38 PM
Comment:
It is very interesting article. How can I insert this array into SQL database? Please Help. Thank you.

Dung Vu
vincenthuyvu@sbcglobal.net

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 5:20:24 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search