Database
  Home arrow Database arrow Page 2 - Reading and Writing to Files on the Intran...
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
eWeek
 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? 
DATABASE

Reading and Writing to Files on the Intranet
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2006-10-10

    Table of Contents:
  • Reading and Writing to Files on the Intranet
  • Opening the Stream Object
  • Can you read text in another language?
  • Writing to a file with an HTM extension
  • Reading and writing binary files

  • 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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Reading and Writing to Files on the Intranet - Opening the Stream Object
    (Page 2 of 5 )

    In the previous article a couple of ways to open a stream object were described with examples as shown. Opening the Stream object with the URL will be used in this tutorial. However, opening the Stream object without any argument offers you the possibility of accessing elements not related to the intranet. Here are some of the ways you can open a Stream object:

    • Record opens with an open recordset and Stream uses the open Record.
    • Open a Stream using an open Record Object.
    • Open a Stream using an URL reference.
    • Open a Stream with no argument by using the Memory Stream.

    Reading and writing text with the Stream Object

    While the Record object deals with accessing and manipulating folders and files, the Stream object deals with what is contained in the files. The Record object can create files as described in a previous tutorial, and the Stream object can access, read from and write to these files.

    The Stream object deals with two kinds of file content, text and binary. For this purpose it has several properties and methods which were not covered in the basic tutorial on the Stream object.  They will  be described with examples here.

    Reading a text file on the intranet

    The ReadText() method reads a specified number of characters from a Stream object working with a text. The related Type for a stream object is adTypeText. Stream.ReadText(NumChars) will return a string. It can therefore read a number of characters in the stream; an entire line; or the whole content in the stream. If no argument is specified, it reads the entire file.

    An example of reading the text

    The text to be read is on an intranet file, the content of which is shown in the next paragraph.

    Test.text
    It must be remembered that there is nothing more difficult to plan, more difficult of success, nor more dangerous to plan than the creation of a new System.

    The code listing shown in the next paragraph reads the text in the above file and the portion that is read is printed to the immediate screen by the debug statements.

    Option Compare Database
    Dim strm As ADODB.stream
    Private Sub Command0_Click()
    strm = New ADODB.stream
    strm.Charset = "ASCII"
    strm.Type = adTypeText
    Debug.Print "Stream Open"
    strm.Open "url=http://hodentek/DevHome/ASPFree/Test.txt", adModeReadWrite
    'Reading the text here
    Debug.Print "---------------reads a single line from the stream-----"
    Debug.Print strm.ReadText(ADODB.StreamReadEnum.adReadLine)
    Debug.Print "-------------------------------------------------------"
    Debug.Print "------------------read 6 characters-------------"
    Debug.Print strm.ReadText(6)
    Debug.Print "----------------------------------------------"
    Debug.Print "------------------read 10 characters--------------------"
    Debug.Print strm.ReadText(10)
    Debug.Print "-----------------------------------------------"
    'Stream.EOS indicates whether or not the stream has ended
    'if some content is still in left in the stream the End Of Stream(EOS) is
    'false
    MsgBox(strm.EOS)
    Debug.Print strm.ReadText()
    Debug.Print "-----------------------------------------------"
    strm.Close
    Debug.Print "Stream Closed"
    Debug.Print "-------------------------" & vbCrLf
    Set strm = Nothing
    End Sub
    

    The result of the above reading is printed to the immediate window as shown below.

    Stream Open
    ---------------reads a single line from the stream-----
    It must be remembered that there is nothing more difficult to plan,
    -------------------------------------------------------
    ------------------read 6 characters-------------
    more d
    ----------------------------------------------
    ------------------read 10 characters--------------------
    ifficult of
    -----------------------------------------------
     success, nor more dangerous to plan than the
    creation of a new System -----------------------------------------------
    Stream Closed
    -------------------------
    

    When you call the ReadText() method without any argument as in the previous listing, the End of File becomes true as what is left of the stream is completely read by the last read, stream.ReadText()..

    More Database Articles
    More By Jayaram Krishnaswamy


       · This is a powerful procedure, but use it with caution. Any procedure that gives...
     

    DATABASE ARTICLES

    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005
    - Manipulating ADO Recordsets




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway