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.
Next: Writing to a file with an HTM extension >>
More Database Articles
More By Jayaram Krishnaswamy