Laden...

Eine Datei zum Download anbieten

Erstellt von jan223 vor 16 Jahren Letzter Beitrag vor 16 Jahren 5.550 Views
jan223 Themenstarter:in
460 Beiträge seit 2004
vor 16 Jahren
Eine Datei zum Download anbieten

Beschreibung:

So kann man eine beliebige Datei mittels ASP.NET zum Download anbieten

/// <summary>
/// Starts the download.
/// </summary>
/// <param name="path">The path.</param>
private static void StartDownload(string path)
{
    FileInfo downloadFile = new FileInfo(path);
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", downloadFile.Name));
    HttpContext.Current.Response.AddHeader("Content-Length", downloadFile.Length.ToString());
    HttpContext.Current.Response.ContentType = "application/octet-stream";
    HttpContext.Current.Response.WriteFile(downloadFile.FullName);
    HttpContext.Current.Response.End();
}

Schlagwörter: Download, Datei

Quelle: .NET-Snippets