Согласно краткому веб-поиску, правильные типы пантомимы для word и excel:
application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
http://www.bram.us/2007/05/25/office-2007-mime-types-for-iis/
Редактировать:
У меня работает следующий упрощенный образец. Он отличается от вашего тем, что он использует универсальный обработчик вместо веб-формы (которая в любом случае больше подходит для чего-то подобного).
Чтобы проверить это, убедитесь, что в папке верхнего уровня приложения есть файл Excel 2007 с именем Book1.xlsx.
DownloadSpreadsheet.ashx:
<%@ WebHandler Language="C#" Class="DownloadSpreadsheetHandler" %>
using System;
using System.Web;
using System.IO;
public class DownloadSpreadsheetHandler: IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
string path = context.Server.MapPath("~/Book1.xlsx");
using (FileStream spreadsheet = File.OpenRead(path))
{
CopyStream(spreadsheet, context.Response.OutputStream);
}
}
public bool IsReusable {
get {
return false;
}
}
private static void CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[32768];
while (true)
{
int read = input.Read(buffer, 0, buffer.Length);
if (read <= 0)
return;
output.Write(buffer, 0, read);
}
}
}