?
Solved

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

Posted on 2006-06-24
6
Medium Priority
?
859 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
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

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.

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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

771 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