Ado Stream in ASP
ADO Stream in Classic ASP is an object used to work with binary or text data—commonly for reading/writing files, handling images, or processing large text/binary data from a database.
What is ADO Stream?
It lets you read/write binary or text data as a stream.
Useful for handling files, images, documents, or blobs in databases.
Supports different types like text and binary.
Creating and Using ADO Stream in ASP
Example: Save Text to a File Using ADO Stream
<%Dim streamSet stream = Server.CreateObject("ADODB.Stream")' Specify stream type (2 = text)stream.Type = 2 ' Open the streamstream.Open' Write text datastream.WriteText "Hello from ADO Stream!"' Save to file on serverstream.SaveToFile Server.MapPath("output.txt"), 2 ' 2 = overwrite if exists' Close the streamstream.CloseSet stream = Nothing%>Example: Read a File Using ADO Stream
<%Dim stream, contentSet stream = Server.CreateObject("ADODB.Stream")stream.Type = 2 ' Text modestream.Openstream.LoadFromFile Server.MapPath("output.txt")' Read all textcontent = stream.ReadTextResponse.Write "File content:<br>" & Server.HTMLEncode(content)stream.CloseSet stream = Nothing%>Important Properties & Methods
| Property / Method | Purpose |
|---|---|
.Type | Data type: 1 = binary, 2 = text |
.Open | Open the stream |
.Close | Close the stream |
.LoadFromFile(path) | Load data from a file |
.SaveToFile(path, options) | Save data to a file (1=fail if exists, 2=overwrite) |
.WriteText(text) | Write text data |
.ReadText | Read text data |
.Write | Write binary data |
.Read | Read binary data |
Use Cases
Storing or retrieving images or documents from a database BLOB field.
Reading/writing files on the server without filesystem calls.
Manipulating large text or binary data streams efficiently.
Would you like a detailed example on uploading an image to database using ADO Stream or downloading files from ASP with ADO Stream?