brian2k1
asked on
Odd Characters after using TextStream
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)
Output Text: “C†Hold
also converts apostrophe's to ’
Filepath = Server.MapPath("testfolder
If FSO.FileExists(Filepath) Then
Dim Contents
Set TextStream = FSO.OpenTextFile(Filepath,
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)
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 =-
<%
Set TextStream = FSO.OpenTextFile(Filepath,
Set TextStream = FSO.OpenTextFile(Filepath,
%>
-= DeathToSpam =-
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("Scrip ting.FileS ystemObjec t")
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 =-
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("Scrip
If FSO.FileExists(Filepath) Then
'// Settings as you had: ForReading, Do Not Create, Open As ASCII
Set TextStream = FSO.OpenTextFile(Filepath,
Contents = TextStream.ReadAll
TextStream.Close
Set TextStream = nothing
End If
Set FSO = Nothing
%>
-= DeathToSpam =-
ASKER
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.
If you found a reference link or something describing this problem please feel free to list it here.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
ASKER
Is there a way to specify the enconding as I did in .Net in ASP (VBScript)?