Solved

Issues with 'OpenAsTextStream' when trying to read/write to a file....

Posted on 2006-06-24
6
785 Views
Last Modified: 2012-05-05
I have the following code at the start of an ASP file.....

      'Create a File System Object variable
      Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")
      
      'Create the path to the count file, and store as string
      sFilenameCountPath = Server.MapPath("custData\count.txt")
      
      'Initialise a File Object with the path and name of count text file to open
      Set filObjectCount = fsoObject.OpenTextFile(sFilenameCountPath, 8, TRUE)
      
      'Open the count text file
**      Set tsObjectCount = filObjectCount.OpenAsTextStream

        ...........then some processing form data and directing to a thankyou page..................

When running the ASP, I am getting the following error at the line marked with an asterix.....

Microsoft VBScript runtime  error '800a01b6'

Object doesn't support this property or method: 'OpenAsTextStream'


Any suggestions as to what I am doing wrong?  I've read around and what I have looks pretty standard...

thanks
0
Comment
Question by:RichardStarkey
  • 3
  • 2
6 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 16977186
>>Object doesn't support this property or method: 'OpenAsTextStream' <<
That is correct the TextStream class (filObjectCount) does not support the OpenAsTextStream

Typically you either use OpenTextFile or OpenAsTextStream, not both.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 125 total points
ID: 16977197
Your code should look something like this:

Dim ts

' Create a File System Object variable
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")
     
' Create the path to the count file, and store as string
sFilenameCountPath = Server.MapPath("custData\count.txt")
     
'Initialise a TextStream object with the path and name of count text file to open
Set ts = fsoObject.OpenTextFile(sFilenameCountPath, 8, TRUE)

ts.WriteLine "This is a line that ends in a vbCrLf"

ts.Close

Set ts = Nothing
Set fsoObject = Nothing
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 16977207
RichardStarkey,

You don't need both OpenTextFile and OpenAsTextStream.  The object is already opened by the first one and errors when you try to open it again.  Both objects will return a textstream object that can be used to access the file.  Choose the method that will provide you what you need.  If you want to use the OpenAsTextStream then specify the file using GetFile.  This page (http://www.w3schools.com/asp/met_openastextstream.asp) has a basic example of using the method.

If you have a question or need more information then please let me know.

b0lsc0tt
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 16977211
Sorry for the duplication.  Acperkins comment has everything you need.  The only thing my comment adds is an example of how you can use the OpenAsTextStream method if you want to use that one instead.

bol
0
 

Author Comment

by:RichardStarkey
ID: 16977263
thanks guys....

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 16979162
"B" grade?
Was there something I missed?
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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 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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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