Generally, in the ASP environment, we use FSO when running live and static operations. It is a component that specializes in operating files. It has only three encoding attributes of FSO. The system defaults are Unicode and ASCII, and there is no utf-8 we want. Therefore, the files generated by using FSO components on the Chinese system are in gb2312 format. Even if you write charset="utf-8" on the web page, it is useless.
To generate a file in utf-8 format, in the ASP environment, we use ADODB.Stream instead of FSO to read and write utf-8 files, because ADODB.Stream has a CharSet property that allows you to define the encoding type of the file to be opened or written. In this way, ADODB.Stream is not only a file that can only read or write utf-8, but basically any format of files can be operated. Of course, what is more useful to us at present is to write files in utf-8 format.
The following function can implement these functions:
FunctionWriteToFile(FileUrl,Str,CharSet)
Setstm=CreateObject("Adodb.Stream")
stm.Type=2
stm.mode=3
stm.charset=CharSet
stm.Open
stm.WriteTextStr
stm.SaveToFileFileUrl,2
stm.flush
stm.Close
Setstm=Nothing
EndFunction
There are many items that can be selected by charset. You can find what you want here: the codePageCharSet display name in Chinese and English. The function of this function is basically the same as the FSO function you use for dynamic and static use, but there is an additional attribute that selects character encoding. Of course, you can also write this attribute directly into the function, but it is better to write this way. If you want to use other items to convert them to other formats in the future, this function can still be used without modifying it.
If you just want to implement batch conversion of existing files to utf-8 format, you can try:
Batch gb2312 to utf-8, support dragging, VBS implementation