none
How to download large file from server ? RRS feed

  • Question

  • Hi all,
       We develop DMS  in asp.net with vb language , which store file,view and download, when download we compress all files as one zip and try to download, using following code

    '' Zip all files
       Dim ZipToCreate As String = Server.MapPath("") + "\TempFiles\" + stringUserName + "\" + stringFolName + ".zip"
            Dim DirectoryToZip As String = Server.MapPath("") + "\TempFiles\" + stringUserName + "\" + stringFolName
            Using zip As ZipFile = New ZipFile(Encoding.UTF8)
                zip.AddDirectory(DirectoryToZip)
                zip.Save(ZipToCreate)
            End Using


        ' Download zip 

            Dim stringFName As String = stringFolName + ".zip"

            Response.ContentType = "application/pdf"
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(stringFName, System.Text.Encoding.UTF8))
            Response.TransmitFile(Server.MapPath("~/TempFiles/" + stringUserName + "/" + stringFolName + ".zip"))
            Response.End()


    We cant download file.

    Note : File not in FTP, it will zip in temp folder inside root folder.
    • Edited by Aravindpanchu Friday, August 17, 2018 9:29 AM updated descritption
    Friday, August 17, 2018 5:56 AM

All replies

  • Hi,

    Do you want a way to download files?

    code:

    Sub getFileFromFTP(ByVal localFile As String, ByVal remoteFile As String, ByVal host As String, ByVal username As String, ByVal password As String)
            Dim URI As String = host & remoteFile
            Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(URI), FtpWebRequest)
            ftp.Credentials = New System.Net.NetworkCredential(username, password)
            ftp.KeepAlive = False
            ftp.UseBinary = False
            ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
            Using response As System.Net.FtpWebResponse = CType(ftp.GetResponse, System.Net.FtpWebResponse)
                Using responseStream As IO.Stream = response.GetResponseStream
                    Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
                        Dim buffer(2047) As Byte
                        Dim read As Integer = 0
                        Do
                            read = responseStream.Read(buffer, 0, buffer.Length)
                            fs.Write(buffer, 0, read)
                        Loop Until read = 0 'see Note(1)
                        responseStream.Close()
                        fs.Flush()
                        fs.Close()
                    End Using
                    responseStream.Close()
                End Using
                response.Close()
            End Using
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 17, 2018 6:57 AM
  • Since it is not PDF, have you tried “application/zip” instead of “application/pdf”?

    What happens when you click the download link?

    For ASP-specific issues, see also: https://forums.asp.net.



    • Edited by Viorel_MVP Friday, August 17, 2018 7:43 AM
    Friday, August 17, 2018 7:43 AM
  • Hi, small size file like 10 to 100mb file can download, i mean 100 mb zip file can download,if more that 500mb got issues.
    Friday, August 17, 2018 9:31 AM
  • Hi,

    Do you want a way to download files?

    code:

    Sub getFileFromFTP(ByVal localFile As String, ByVal remoteFile As String, ByVal host As String, ByVal username As String, ByVal password As String)
            Dim URI As String = host & remoteFile
            Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(URI), FtpWebRequest)
            ftp.Credentials = New System.Net.NetworkCredential(username, password)
            ftp.KeepAlive = False
            ftp.UseBinary = False
            ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
            Using response As System.Net.FtpWebResponse = CType(ftp.GetResponse, System.Net.FtpWebResponse)
                Using responseStream As IO.Stream = response.GetResponseStream
                    Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
                        Dim buffer(2047) As Byte
                        Dim read As Integer = 0
                        Do
                            read = responseStream.Read(buffer, 0, buffer.Length)
                            fs.Write(buffer, 0, read)
                        Loop Until read = 0 'see Note(1)
                        responseStream.Close()
                        fs.Flush()
                        fs.Close()
                    End Using
                    responseStream.Close()
                End Using
                response.Close()
            End Using
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Hi , file not is FTP, it will compress in temp folder inside root folder which we deployed,  i means
    C:\inetpub\wwwroot\webTesting\Temp, webtesting is our web application, files zipped in Temp folder under WebTesting.
    Friday, August 17, 2018 9:33 AM
  • Since it is not PDF, have you tried “application/zip” instead of “application/pdf”?

    What happens when you click the download link?

    For ASP-specific issues, see also: https://forums.asp.net.



    When click download i use above code to download from server, file store in Temp folder under webTesting , means C:\inetpub\wwwroot\webTesting\Temp, webtesting is our web application, files zipped in Temp folder under WebTesting.
    Friday, August 17, 2018 9:36 AM
  • This may boil down to an ISS setting, see the following.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, August 17, 2018 1:53 PM
    Moderator