Solved

Odd Characters after using TextStream

Posted on 2006-11-16
6
760 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
ID: 17963278
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
ID: 17965312
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
ID: 17965468
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:brian2k1
ID: 17965593
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
ID: 17965690
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
ID: 17965850
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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