Implementation of server-side file selection with XML+FSO+JS in ASP

Source: Internet
Author: User

First create a program on the server side to generate an XML file to return to the client, (getfolder.asp)

<%
' Written by Linzhang Chen, 2003-4-20
' Reprint please indicate the source and retain this copyright information
Response.Write "<?xml version=" "1.0" "encoding=" "GB2312" "?>" &AMP;CHR (13)
Response.Write "<mediafile>" &AMP;CHR (13)
Folders=request ("folder")
If folders= "/" Then
Folders= ""
End If
Dim count
Count=0
Folders=replace (folders, "..", "")
Basefolder= ". /media/"' Reference to the folder path
Newfolder=basefolder&folders
Set FSO =server. CreateObject ("Scripting.FileSystemObject")
Set F=fso.getfolder (Server.MapPath (NewFolder))
Set Sf=f.subfolders
For each FD in SF ' returns the list of folders below the specified path
Response.Write "<file>" &AMP;CHR (13)
Response.Write "<ftype>folder</ftype>" &AMP;CHR (13)
Response.Write "<fname>" &fd.name& "</fname>" &AMP;CHR (13)
Response.Write "</file>" &AMP;CHR (13)
Count=count+1
Next
Set sf=nothing
Set Ff=f.files
For each fi in FF
Fname=fi.name
If InStr ("Asf,wma,wmv", LCase (Mid (Fname,instrrev (fname, ".") +1)) >0 Then ' set the file type to allow return, prevent source leakage
Response.Write "<file>" &AMP;CHR (13)
Response.Write "<ftype>file</ftype>" &AMP;CHR (13)
Response.Write "<fname>" &fname& "</fname>" &AMP;CHR (13)
Response.Write "</file>" &AMP;CHR (13)
Count=count+1
End If
Next
' If there is no file in the directory, send an empty element
If Count=0 Then
Response.Write "<file>" &AMP;CHR (13)
Response.Write "<ftype>empty</ftype>" &AMP;CHR (13)
Response.Write "<fname>0</fname>" &AMP;CHR (13)
Response.Write "</file>" &AMP;CHR (13)
End If
Response.Write "</mediafile>"
Set ff=nothing
Set f=nothing
Set fso=nothing
%>

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.