Solved

Odd Characters after using TextStream

Posted on 2006-11-16
6
758 Views
Last Modified: 2009-07-29
Original Text: “C” Hold
Output Text: “C” Hold

also converts apostrophe's to ’

Filepath = Server.MapPath("testfolder/test.htm")

If FSO.FileExists(Filepath) Then
      Dim Contents
      Set TextStream = FSO.OpenTextFile(Filepath, ForReading, False, TristateUseDefault)            
            Contents = TextStream.ReadAll
            TextStream.Close
      Set TextStream = nothing
End If

I would like to know what is causing this and how to correct it.

Server: IIS6
Language: ASP (VBScript)
0
Comment
Question by:brian2k1
  • 3
  • 3
6 Comments
 
LVL 1

Author Comment

by:brian2k1
Comment Utility
I found a solution to this problem using VB.Net by adding the Encoding.Default to the code.

Is there a way to specify the enconding as I did in .Net in ASP (VBScript)?
0
 
LVL 9

Expert Comment

by:deathtospam
Comment Utility
Try either of these to see if there's any change in what is assigned to the [TextStream] variable:

<%
Set TextStream = FSO.OpenTextFile(Filepath, ForReading, False, -1)
Set TextStream = FSO.OpenTextFile(Filepath, ForReading, False, 0)
%>


-= DeathToSpam =-
0
 
LVL 9

Expert Comment

by:deathtospam
Comment Utility
Brian2k1 --

Here's a test script I wrote up, which returns [“C” Hold]:

<%
'// [FilePath] is assigned a valid path, relative or absolute.
Set FSO = Server.CreateObject("Scripting.FileSystemObject")

If FSO.FileExists(Filepath) Then
     '// Settings as you had: ForReading, Do Not Create, Open As ASCII
     Set TextStream = FSO.OpenTextFile(Filepath, 1, False, 0)          
          Contents = TextStream.ReadAll
          TextStream.Close
     Set TextStream = nothing
End If

Set FSO = Nothing
%>


-= DeathToSpam =-
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:brian2k1
Comment Utility
That didn't work for me. Looks like the only thing that changed in the code you presented from my original is the "TristateUseDefault" to a 0 (zero). I also tried -1 which just turned it all into garbage.

If you found a reference link or something describing this problem please feel free to list it here.
0
 
LVL 9

Accepted Solution

by:
deathtospam earned 500 total points
Comment Utility
Yeah, sorry -- that comment should have read "Settings as you had, with Open As ASCII".  

I was just following MSDN's documentation on the OpenTextFile method ( http://tinyurl.com/czoe7 ).  It only provides two options: opening a text file as Unicode (-1) or ASCII (0).  What was displayed when you ran my code?  Can you check the source code of the webpage and see if it's the same there?


-= DeathToSpam =-
0
 
LVL 1

Author Comment

by:brian2k1
Comment Utility
The function listed below along with a charset of "utf-8" reproduces the same results as I got with .Net code.

http://www.motobit.com/tips/detpg_read-write-binary-files/

Function ReadTextFile(FileName, CharSet)
  Const adTypeText = 2
 
  'Create Stream object
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")
 
  'Specify stream type - we want To get binary data.
  BinaryStream.Type = adTypeText
 
  'Specify charset For the source text (unicode) data.
  If Len(CharSet) > 0 Then
    BinaryStream.CharSet = CharSet
  End If
 
  'Open the stream
  BinaryStream.Open
 
  'Load the file data from disk To stream object
  BinaryStream.LoadFromFile FileName
 
  'Open the stream And get binary data from the object
  ReadTextFile = BinaryStream.ReadText
End Function

so who knows the correct charset to get my text back the way it should be?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now