Solved

ASP.net File download not working

Posted on 2016-08-06
2
46 Views
Last Modified: 2016-08-06
Hi

I have the following code in my ASP.net site to download a zipped file that contains a .exe file.
It works fine in debug mode but nothing seems to happen at the following site address
http://automaticoffice.azurewebsites.net/Downloads
It is the first image button with the title (1) Standalone Access solution

    Protected Sub ImageButton1_Click(sender As Object, e As ImageClickEventArgs) Handles ImageButton1.Click

        Dim filename As String = Server.MapPath("~/Download_File/Automator_Installs.zip")
        Dim fileInfo As New System.IO.FileInfo(filename)

        If fileInfo.Exists Then
            Response.Clear()
            Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name)
            Response.AddHeader("Content-Length", fileInfo.Length.ToString())
            Response.ContentType = "application/octet-stream"
            Response.Flush()
            Response.TransmitFile(fileInfo.FullName)
            Response.[End]()
        End If
    End Sub
0
Comment
Question by:murbro
2 Comments
 
LVL 8

Accepted Solution

by:
Prakash Samariya earned 500 total points
ID: 41745466
Wild guess, Please try something like below

Dim filename As String = Server.MapPath("~/Download_File/Automator_Installs.zip")
Dim fileInfo As New System.IO.FileInfo(filename)

'Set  content type for downloading file
Response.AddHeader("content-disposition", "attachment;filename="+fileInfo.Name )
Response.ContentType = "application/vnd.xls"
Response.Charset = ""
Response.TransmitFile(fileInfo.Name)
Response.Flush()
Response.Close()
Response.End()

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 41745938
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What .NET website keeps me current? 9 57
Achieve json result 2 65
SSRS ReportViewer report timeout 7 104
Syntax Error 2 46
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now