[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-06-24
6
Medium Priority
?
901 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 375 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 informatio…
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…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

873 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