// full path to your file //var yourFilePath = HttpContext.Current.Request.PhysicalApplicationPath + "Files\yourFile.jpg"; // save downloaded file as (name) //var saveFileAs = "yourFile.jpg"; // start force download of your file //Response.ForceDownload(yourFilePath, saveFileAs); public static void ForceDownload(this HttpResponse Response, string fullPathToFile, string outputFileName) { Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=" + outputFileName); Response.WriteFile(fullPathToFile); Response.ContentType = ""; Response.End(); }
Monday, January 30, 2012
Best Extension Methods: Force Download a File
Below Extension method is for Force Download a file
Share This!
Labels:
C#.NET,
Extension Methods
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment