Comment télécharger les fichiers à l'aide de vbscript en asp classique

Je suis en train de travailler sur l'Asp Classique avec VBScript. J'essaie d'afficher la liste des fichiers d'un répertoire avec l'option de téléchargement. comme,Comment télécharger les fichiers à l'aide de vbscript en asp classique

Quand je clique sur le lien télécharger le fichier correspondant doivent être télécharger pour ce que j'ai utilisé le code suivant comme,

<html>
<head>
<title> My First ASP Page </title>
</head>
<body>
<%
Dim fso
Dim ObjFolder
Dim ObjOutFile
Dim ObjFiles
Dim ObjFile
'Creating File System Object
Set fso = CreateObject("Scripting.FileSystemObject")
'Getting the Folder Object
Set ObjFolder = fso.GetFolder("F:\karthik")
'Creating an Output File to write the File Names
Set ObjOutFile = fso.CreateTextFile("F:\WindowsFiles.txt")
'Getting the list of Files
Set ObjFiles = ObjFolder.Files
'Writing Name and Path of each File to Output File
Response.Write("<table cellpadding=""4"" cellspacing=""5"" >")
For Each ObjFile In ObjFiles
Response.Write("<tr><td>"&ObjFile.Name & String(50 - Len(ObjFile.Name), " ")&"</td><td><a href=""#"" language=""VBScript"" onclick=""vbscript:HTTPDownload('"&ObjFile.Path&"','C:\Users\stellent\Downloads\')"">Download</a></td></tr>")
Next
Response.Write("</table>")
ObjOutFile.Close
%><br>
<script language="vbscript" type="text/vbscript">
Sub HTTPDownload( myURL, myPath )
' Standard housekeeping
Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Create a File System Object
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
' Check if the specified target file or folder exists,
' and build the fully qualified path of the target file
If objFSO.FolderExists( myPath ) Then
strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
strFile = myPath
Else
WScript.Echo "ERROR: Target folder not found."
Exit Sub
End If
' Create or open the target file
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )
' Create an HTTP object
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
' Download the specified URL
objHTTP.Open "GET", myURL, False
objHTTP.Send
' Write the downloaded byte stream to the target file
For i = 1 To LenB( objHTTP.ResponseBody )
objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next
' Close the target file
objFile.Close( )
End Sub
</script>
</body>
</html>
  • .. et ce qui se passe ? est le téléchargement qui se passe ?
  • Oui.. Pas de téléchargement de passe. Je pense que ma balise d'ancrage ne marche pas appel de méthode vbscript.
  • c'est un fichier asp, pas de vbs. vous devrez mettre le code dans le bloc de script en asp balises et d'essayer. le lien devra faire une publication et d'appeler la fonction de téléchargement
  • Ok. pourriez-vous nous dire comment appeler la méthode d'ancrage tag cliquez sur l'événement depuis que je suis un débutant en asp.