C# .NET - using Response.Redirect to open documents. working(txt,jpg,csv) but not xls or xlsx

Asked By Pranay on 12-Feb-13 02:04 PM
I'm trying display documents stored in a folder(@ server) through my application. I'm response.redirect and its working fine for txt, jpg, and csv files but for some reason excel files are not being displayed.  Files with extension .xls open with encoded text and .xlsx files prompt users to open a zip file. Any suggestions to what is going wrong here. I've microsoft excel installed at the system from which i was using the app.
Thanks
Robbe Morris replied to Pranay on 12-Feb-13 06:06 PM
Post your code.  You need to set the ContentType attribute of the Response object prior to writing file to the Response stream.
Response.Clear();
Response.Buffer = true;
Response.StatusCode = 200;
Response.ContentType = "application/vnd.ms-excel";
Response.WriteFile("C:\rob.xls");