WebClient client = new WebClient(); Byte[] buffer = client.DownloadData("File path here"); Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=" + ViewState["Cont"].ToString()); //Response.ContentType = "application/octet-stream"; Response.ContentType = MimeType(Path.GetExtension("File name here")); Response.Buffer = true; Response.OutputStream.Write(buffer, 0, buffer.Length); Response.OutputStream.Flush(); Response.End(); //this is function to get file extension public static string MimeType(string Extension) { string mime = "application/octetstream"; if (string.IsNullOrEmpty(Extension)) return mime; string ext = Extension.ToLower(); Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext); if (rk != null && rk.GetValue("Content Type") != null) mime = rk.GetValue("Content Type").ToString(); return mime; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)