asp.net - Cannot download exe files through c#.net -
I have created a website through which when I click the .EXE file on a button, Should be downloaded from a specific path. / P>
But instead of downloading the ASPX page of the website, it is not to download the XI file.
I use the following code:
WebClient myWebClient = new WebClient (); // Insert domain with web resource file name MyWebClient.DownloadFile ("http: // localhost: 1181 / compile / compiler / sample 2.exe", "sample2.exe");
Would you please try it.
string file name = "yourfilename"; If (file name! = "") {String path = Server.MapPath (filename); System.IO.FileInfo file = New System.IO.FileInfo (path); If (file.Exists) {Response.Clear (); // Content-Displacement will tell the browser how to handle files. (For example, in the case of a JPG file, either to display the file in the browser or to download it) // Here the key is the importance of the attachment. Which is reporting browsing as an attachment and name that is displayed on the download dialog Reply.AddHeader ("Content Disposition", "Attachment; filename =" + file.Name); // to tell the length of the material .. response. Response to the adheender ("content-length", file type.lang.file, whether it is an exe, pdf, jpeg etc. etc. Contact respond type = "app / octet-stream"; // in return for the client Writing the content of the file .. WrititeFile (file.FullName); Response.End ();} Else {Response.Write ("This file does not exist.");}} I hope that my edited comment will help you understand. But note: this is just a difficult summary. You can do a lot more than this.
Comments
Post a Comment