我在temp文件夹中有五个文件可下载该文件。我的目的是下载所有文件,但现在下载第一个文件。
我尝试使用此代码下载所有文件
将strSrcFolder设置为String = Server.MapPath(“〜/ TempFiles / senthil / PDF /”) 昏暗的dinfo作为新的DirectoryInfo(strSrcFolder) 对于每个finfo作为dinfo.GetFiles()中的FileInfo Dim stringFName As String = finfo.Name
Response.ContentType = "application/pdf"
Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(stringFName, System.Text.Encoding.UTF8))
Response.TransmitFile(Server.MapPath("~\TempFiles\senthil\PDF\" + stringFName))
Response.End()
Next
答案 0 :(得分:-1)
Dim i As Integer
Dim TxtLocalSysName As String = Request.UserHostName
Dim readStream As FileStream
Dim writeStream As FileStream
Try
For i = 0 To lstdownload.Items.Count - 1
Dim filePath As String = Me.Label5.Text + "\" + lstdownload.Items(i).Text
Dim targetFile As System.IO.FileInfo = New System.IO.FileInfo(filePath)
readStream = New FileStream(filePath, FileMode.Open)
Dim length As Integer = Convert.ToInt32(readStream.Length)
'This is the buffer.
Dim byteFile() As Byte = New Byte(length) {}
readStream.Read(byteFile, 0, length)
readStream.Close()
Dim localPath As String = "\\" & TxtLocalSysName & "\c$\downloads"
If Not Directory.Exists(localPath) Then
Directory.CreateDirectory(localPath)
End If
writeStream = New FileStream(localPath & "\" & targetFile.Name, FileMode.Create)
writeStream.Write(byteFile, 0, length)
writeStream.Close()
Next i
Catch ex As Exception
Console.WriteLine("The process failed: {0}", ex.ToString())
Finally
readStream.Close()
readStream.Dispose()
writeStream.Close()
writeStream.Dispose()
End Try