Non-component uploading program with ADO stream

Source: Internet
Author: User
Tags uuid
With ADO stream without component upload program, today I do a brief introduction to it

Previously, if you want to use ASP operation files, such as mobile, copy, delete or create a Notepad file, basically through the FileSystemObject object, of course, this thing is very professional, also did not say what bad, it can provide perfect file information, such as the establishment of time, size, Last modified time, and so on, but if you don't make painful high cost character format conversions, you can't manipulate binary files directly using it.

However, the stream object we are introducing now can manipulate both the text object and the binary object, requiring that the ADO2 be installed on your machine. 5 or later, you can go down from the http://www.microsoft.com/data.

This stream object contains a number of ways to manipulate binary and text files, so let's take a look at the examples.

Open 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 reference, if you do not understand the place, you can see my previous post, what the specific name of the forgotten

Note: If the version does not indicate an error message for the above code. Now that you have established a 0-length stream, you can use the Size property to see the change stream at any time, and now we want to specify what type of information to manipulate, binary or text, and, if it is text, whether ASCII or Unicode format

The following code:
objStream.Type = adTypeText
Objstream.charset = "ASCII"

Next we write a text file into this stream, using its LoadFromFile method

objStream.LoadFromFile "D:\Inetpub\wwwroot\webtech\083100-1.shtml"

It is important to note here that if you operate the stream, be sure to understand the concept of location, here we use the LoadFromFile method, the original stream content will be completely cleared, and then, the file is loaded into the stream, and then the stream position restored to 0 , (start position of stream)
If you write the information in the current 0 position, you will overwrite the original content, so if you want to add something, you must start from the last position, the following code:

Objstream.position = Objstream.size

The code moves the current position to the last

Now we can add something to the back, hey, like

Objstream.writetext "Please visit my chat room, mm especially welcome"

Ha ha
Now that we've reached our goal, let's keep it down here to pay attention to is because you are using Iuser_machinename account, so the corresponding directory to the account open Write permission, this is no way, otherwise it will be wrong.

Objstream.savetofile "D:\InetPub\wwwroot\demos\StreamDemo.txt", Adsavecreateoverwrite

Inherit our fine tradition, after use, turn off the release

' Close the stream and set it to nothing ...
objStream.Close
Set objstream = Nothing
%>

As I have said before, it can also manipulate binary objects, in fact, as long as the modification of some parameters on it, let's take a look at an example:

<!--METADATA type= "TypeLib"
Uuid= "00000205-0000-0010-8000-00AA006D2EA4"
Name= "ADODB Type Library"
-->
<%
' Create a Stream object
Dim objstream
Set objstream = Server.CreateObject ("ADODB. Stream ")

' Open a GIF file
objStream.Type = adTypeBinary
objStream.Open
objStream.LoadFromFile "D:\Inetpub\wwwroot\images\banner\dimacbanner1.gif"

' Output the contents of the Stream object
Response.ContentType = "Image/gif"
Response.BinaryWrite Objstream.read

' Clean up ....
objStream.Close
Set objstream = Nothing
%>

You can try this to write a upload of things, so learn fast, anyway there are ready-made teachers in, can refer to


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.