ASP.NET
  Home arrow ASP.NET arrow Page 4 - Reading a Delimited File Using ASP.Net and...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Reading a Delimited File Using ASP.Net and VB.Net
By: G Ajaykumar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 106
    2003-10-15

    Table of Contents:
  • Reading a Delimited File Using ASP.Net and VB.Net
  • Usage
  • Example Code
  • Example Code, Cont'd
  • Code Explanation
  • Output

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Reading a Delimited File Using ASP.Net and VB.Net - Example Code, Cont'd


    (Page 4 of 6 )

    After we’ve specified the delimiter, we now split the contents of the files using the specified delimiter.  In order to do that we’ll declare a variable named splitout.  We’ll then use the split function to split the text.
       
    Dim splitout = Split(readcontents,textdelimiter)
       
    In the above code we have declared a variable named splitout.  To that variable we are assigning split functionality.

    The Split function contains two parameters: the first is the content, the second is the delimiter.  The contents of the file are split according to the delimiter passed.  The split contents are then stored in the form of arrays.  To exhibit the output we will use two asp: labels, whose text will be assigned dynamically.  Let us place a label out of the </script> tag

    <asp:label runat="server" id="lblsplittext">

    The above tag should be placed outside of the </script> tag.

    Now we declare a variable i with data-type integer, which is used for looping:

    dim i as integer

    Now we will be using a for loop to read the contents which are stored in the arrays:

    for i=0 to Ubound(splitout)

    In the above code, Ubound(splitout) specifies the upper limit of the array splitout –  splitout is the variable which contains the split text. Here you may be wondering how splitout has become an array.  Whenever you use the split function, the variable that is used for splitting is automatically converted into an array.
     
    Starting from zero which is our lower limit until the upper limit we write the text to the asp:label .

    lblsplittext.Text &= "<b>Split </b>" & i+1 & ")   " & splitout(i)& "<br>"

    In the above code, using lblsplittext.text we dynamically assign the value to the asp:label named lblsplittext.  We’ll take a look at the next section of that code.

    Here we use the <b> (bold) tag, which is a normal HTML tag.  Here, it’s simply used to bold the text.  We then concatenate the variable i which is in the loop (i displays a serial number)

    "<b>Split </b>" & i+1 & ")  

    In the next part

    " & splitout(i)& "<br>"

    We are concatenating the variable splitout (i), which we would see that variable i is passed to the splitout variable.  Here the concept of passing i is as follows:  We know that splitout is an array, the lower limit of an array starts from zero.  Since this splitout(i) is within the loop, the variable passes from the lower limit to the upper limit, when it goes through loop it looks like this:

    splitout(0), then splitout(1), then splitout(2) until the upper limit.

    To navigate to the next array element using the for loop then we use the Next key word.  In order to differentiate the file contents and the read delimited contents, we shall display the files contents to an asp: label directly – which is raw without any split.  Now let us place the tag after the </script> tag

    <asp:label runat="server" id="lblplaintext">

    We dynamically assign the label’s text with the contents read from the file.

    lblplaintext.text = readcontents & "<br>"

    In the code above, we concatenate a “<br>” just to break the line (for readability purposes).  Now we close the stream class objecft in order to release the resources:

    filestream.Close()  

    After we close the stream object, we close the subroutine, and close the script tag:

    End Sub
    </script>

    After closing the script tag we will be placing the asp: label (as previously explained) and some text:

    <b>Plain Output</b><br />
    <Asp: label runat="server" id="lblplaintext" Font-Name="Verdana" />

    <b>Split Output</b><br />
    <Asp: label runat="server" id="lblsplittext" Font-Name="Verdana" />

    The above tags create two asp: labels, whose text are assigned dynamically, which are merely used for display purposes.

    That’s it!  We have gone through the complete procedure for reading a delimited text file.

    More ASP.NET Articles
    More By G Ajaykumar


       · hi!nice code.i have a little problem as i m using ur code but if my .txt file...
       · This was an excellent article. I found it very logically laid out and clearly...
     

    ASP.NET ARTICLES

    - 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







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT