2
Answers

download a exe file from my asp page

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:
 
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
Answers (2)
0
habib ullah

habib ullah

NA 116 2k 7y
sir please define the details of the above code
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 7y
You can use Path.GetExtension()
 
string myFilePath = @"C:\Manas.txt";
string ext = Path.GetExtension(myFilePath); //.txt