Someone posted a componentless upload program made with ADO STREAM. Today I will give a brief introduction to it.
In the past, if you wanted to use ASP to operate files, such as moving, copying, deleting or creating a notepad file, it was basically done through the FILESYSTEMOBJECT object. Of course, this thing is very professional and doesn't say anything bad. It can provide complete file information, such as the establishment time, size, last modification time, etc., but if you don't do painful and high-cost character format conversion, you can't directly manipulate binary files with it.
However, now the stream object we introduced can operate both text objects and binary objects. The requirement is that your machine needs to have ADO2.5 or higher version installed, you can go to DOWN from http://www.microsoft.com/data.
This stream object contains many methods for manipulating binary and text files. Let's take a look at the example
Open the stream object
<!--METADATA TYPE=typelib UUID=00000205-0000-0010-8000-00AA006D2EA4 NAME=ADODB Type Library--><%'Create a Stream instanceDim objStreamSet objStream = Server.CreateObject(ADODB.Stream)'Open the streamobjStream.Open
For the above quotes, if you don't understand, you can read the post I posted before, what specific name I forgot
Note: If the version is not correct, the above code will prompt an error message.
Now you have created a 0-length STREAM. At any time, you can use the size attribute to view the size of the stream. Now we want to specify what type of information to operate, binary or text, if it is text, you also need to specify whether it is ASCII or UNICODE format
The following code:
objStream.Type = adTypeText
objStream.Charset = ascii
Next, we write a text file into this stream and use its loadfromfile method
objStream.LoadFromFile D:/Inetpub/wwwroot/webtech/083100-1.shtml
It should be noted here that if you operate the stream, you must understand the concept of location. After we use the loadfromfile method, all the contents in the stream will be cleared, and then the file is loaded into the stream, and then the stream position is restored to 0, (the starting position of the stream)
If you write information at the current 0 position, it will overwrite the original content, so if you want to add something, you must start from the last position, as follows:
objStream.Position = objStream.Size
This code moves the current position to the last
Now we can add something to the back, hehe, for example
objStream.WriteText Please visit my chat room, MM is especially welcome
Ha ha
Now that we have achieved our purpose, let's save it
What you should note here is that because you use the account of iuser_machinename, the corresponding directory must open write permissions to the account. This is impossible, otherwise an error will occur.
objStream.SaveToFileD:/InetPub/wwwroot/demos/StreamDemo.txt, adSaveCreateOverwrite
Inherit our fine traditions and close the release after use
'Close the stream and set it to nothing...