0

I am trying to open a Excel(.xls) file from asp.net.The code i am using is given here.It is showing a save as dialog box which i don't want .Please help me !!!

  Response.ContentType = "application/xls";
  Response.Flush();
  Response.WriteFile(fileName);
  Response.End();

2 Answers 2

1

Try adding response.addheader and use "binarywirte" instead of "writeFile" to your code like below sample code(working code) ...

   System.IO.FileStream fs = null;
        fs = System.IO.File.Open(filename, System.IO.FileMode.Open);

        byte[] btFile = new byte[fs.Length];
        fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
        fs.Close();
        Response.AddHeader("Content-disposition", "attachment; filename=" + filename);
        Response.ContentType = "application/octet-stream";
        Response.BinaryWrite(btFile);
        Response.End();
Sign up to request clarification or add additional context in comments.

Comments

0

This is ultimately controlled through file associations in the operating system.You can modify registry settings on a per machine basis to achieve this result.

You would need to change the subkeys under HKEY_LOCAL_MACHINE\SOFTWARE\Classes that relate to excel. Specifically you have to add the following value:

Name=BrowserFlags; Type=REG_DWORD; Value=8

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.