Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hii All,

m using below code and it is working fine but I have to reload page after download the file,I tried lots of method but It didn't work

C#
 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;
    } 


If any one have any solution plz share

Thanx
Posted

1 solution

Check this answer: Update page after file download[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900