Database
  Home arrow Database arrow Page 3 - 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 
IBM Rational Software Development Conference
 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

    Ajax Application Generator Generate database 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 - Can you read text in another language?
    (Page 3 of 5 )

    It's possible to read the text in another language, for example as shown in the next code listing which reads a quotation in French (from Napoleon) in the file French.htm. Instead of the ASCII charset, you need the 'UTF-8' charset. Since the immediate screen is strictly ASCII, the file opened was saved to a file of type *.doc.

    Option Compare Database
    Private strm As ADODB.stream
    Private Sub Command0_Click()
    Set strm = New ADODB.stream
    strm.Charset = "UTF-8"
    strm.Type = adTypeText
    Debug.Print "Stream Open"
    strm.Open "url=http://hodentek/DevHome/ASPFree/" & _
    "French.htm", adModeReadWrite
    strm.SaveToFile "C:/French.doc", adSaveCreateOverWrite
    End Sub 

    This produces the output as shown written to a Word document using the Stream.SaveToFile statement. Note that some extra characters were added to the beginning of this file before <B> which were not present in the French.htm file. The reason for this is yet to be discovered.

    Writing text to a file on the intranet

    The content of the Test.txt file used in the above example was written using the WriteText() method of the Stream object as shown in the next listing. This example in the code listing shows both filling up an empty file on the intranet with text, as well as persisting the stream content to a file in the folder of the computer.

    Option Compare Database
    Private rec As ADODB.Record
    Private strm As ADODB.stream
    Private Sub Command0_Click()
    Set rec = New ADODB.Record
    rec.Open "DevHome/ASPFree/Test.txt", _
    "URL=http://hodentek/", adModeReadWrite, _
    adCreateOverwrite + adCreateNonCollection
    Set strm = New ADODB.stream
    strm.Type = adTypeText
    strm.Charset = "ASCII"
    strm.Open rec, adModeReadWrite, adOpenStreamFromRecord
    strm.WriteText "It must be remembered that there is nothing more
    difficult to plan,", adWriteLine strm.WriteText "more difficult of success, nor more dangerous to plan
    than the", adWriteLine strm.WriteText "creation of a new System --The Prince", adWriteLine strm.SaveToFile "outputSaveToFile.txt", adSaveCreateOverWrite strm.Flush strm.Close rec.Close End Sub

    Before the code in this listing is run, the ASPFree folder does not have a Test.Txt file as shown in the next pciture.

    After the record is open Test.txt, an empty file, will be created in the ASPFree folder as shown.

    This file will be created with the overwrite option. The Stream object is opened with the Read Write option; it is also allowed to access the record just opened. Then a number of lines of text are written, each ending with the line separator option adWriteline. The Stream.SaveToFile statement creates the file outputSaveToFile.txt in the default directory (My Documents). Again if this file exists, it will be overwritten. The content of this file was shown in the previous section.

    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 3 hosted by Hostway