Solved

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

Posted on 2006-06-24
6
759 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

23 Experts available now in Live!

Get 1:1 Help Now