Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a asp web page with c# code ,i am trying to download an exe file but it download entire web page instead of exe plz help( i am starter)

my requirement : i want to download a exe file from my website using asp and c#

i am trying this code:

C#
protected void btn_download_Click(object sender, EventArgs e)
    {
        string filename = "SherAcc.exe";
        if (filename != "")
        {
            string path = Server.MapPath(filename);
            System.IO.FileInfo file = new System.IO.FileInfo(path);
            if (file.Exists)
            {
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; SheraAcc=" + file.Name);
               
                Response.AddHeader("Content-Length", file.Length.ToString());

                Response.ContentType = "Application/octet-stream";
                Response.WriteFile(file.FullName);
                Response.End();
            }
            else
            {
                Response.Write("This file does not exist.");
            }
        }
    }




The output : downloading the page
note : exe file place in same location of the project no additional folder used
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900