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.
<%@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 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!