Backend-Code Handler.ashx
<%@ WebHandler Language= "C#" Class="Handler" %>
using System;using System.Web
public class Handler: IHttpHandler {
public void ProcessRequest ( HttpContext context) {
string fileName = "web.config";//Der vom Client gespeicherte Dateiname
string filePath = context.Server.MapPath("web.config");//Path
/ /Dateien als Zeichenströme herunterladen
System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open);
byte[] bytes = new byte[( int) fs.Length];
fs.Read(bytes, 0, bytes.Length);
context.Response.ContentType = "application/octet-stream"; 🎜> // Benachrichtigen Sie den Browser, die Datei herunterzuladen, anstatt sie zu öffnen
context.Response.AddHeader("Content-Disposition", "attachment; filename=" HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) );
context.Response.BinaryWrite();
context.Response.End(}
public bool IsReusable {
get {
return false;}
}
}
Front-End-Code:
Code kopieren
Der Code lautet wie folgt:
< head>
<script> <br>function download_file(url) <br><br>if (typeof (download_file.iframe) == "undefiniert") <br>{ <br>var iframe = document .createElement("iframe"); <br>download_file.iframe = iframe; <br>document.body.appendChild(download_file.iframe); warning(download_file.iframe); <br> download_file.iframe.src = url; <br><br>download_file.iframe.style.display = "none"; 🎜></script>
">aaaaa
bbbbb ccccc 🎜>