Solved

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

Posted on 2006-06-24
6
773 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i convert a Generic list to DataTable in c# 3 772
Syntax Help on SP 4 57
API not working 33 56
Forcing form refresh - classic ASP 7 59
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

22 Experts available now in Live!

Get 1:1 Help Now