【问题标题】:How download more than one file using asp.net如何使用asp.net下载多个文件
【发布时间】:2018-09-04 19:00:54
【问题描述】:

我在临时文件夹中有五个文件用于下载该文件。我的目标是下载所有文件,但现在它下载第一个文件。

我尝试使用此代码下载所有文件

Dim strSrcFolder As String = Server.MapPath("~/TempFiles/senthil/PDF/") 将 dinfo 调暗为新 DirectoryInfo(strSrcFolder) 对于每个 finfo 作为 FileInfo 在 dinfo.GetFiles() 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

【问题讨论】:

标签: asp.net


【解决方案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

【讨论】:

  • 嗨,先生,感谢您的回复,我的网站我把服务器端放在服务器端,所以所有的 zip 文件下载在服务器端。我需要使用上面的代码在客户端的所有 zip 文件,请尽快回复 ASPA
猜你喜欢
  • 2014-04-20
  • 1970-01-01
  • 2019-02-03
  • 2013-09-29
  • 1970-01-01
  • 1970-01-01
  • 2015-06-24
  • 1970-01-01
相关资源
最近更新 更多