Как открыть файл Excel?

xaly
Дата: 30.03.2010 10:27:48
На сервере лежит готовый файл excel, как его открыть клиенту?
делаю так, не работает:

 
            Response.ContentType = "application/vnd.ms-excel";
            Response.AppendHeader("Content-disposition", "attachment;filename=Rep_.xls;");
            string filePath = Server.MapPath(".") + @"\Reports\Rep_.xls";
            BinaryWriter writer = new BinaryWriter(Response.OutputStream);
            byte[] fileData = File.ReadAllBytes(filePath);
            writer.Write(fileData);
            writer.Close();
            Response.End();

Вылазит ошибка: Sys.WebForms.PageRequestManagerParserErrorException:
The message receinved from the server could not be parsed. Common causes for this error are when the
response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Зритель с попкорном 5
Дата: 30.03.2010 11:54:48
xaly,

Я пользуюсь вот таким методом объявленным на странице
public void Download(string fileName, string downloadName)
{
	var fi = new FileInfo(fileName);

	base.Response.Clear();
	base.Response.ClearHeaders();
	base.Response.ContentType = "application/octet-stream";
	base.Response.AddHeader("Content-Length", fi.Length.ToString());
	if(base.Request.Browser.IsBrowser("IE"))
	{
		downloadName = HttpUtility.UrlPathEncode(downloadName);
	}
	base.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", downloadName));
	base.Response.Buffer = false;

	base.Response.WriteFile(fileName);

	base.Response.Flush();
	base.Response.End();
}

В вашем случае вызывать его как:
Download(MapPath("~/Reports/Rep_.xls"), "Rep_.xls");
xaly
Дата: 31.03.2010 03:49:45
Зритель с попкорном 5,
Попробовала и вашим способом, ошибка таже самая.

Начала склонятся к тому что, это проблема в office 2007.

Не ужели не у кого не было такой же проблемы?
Зритель с попкорном 5
Дата: 31.03.2010 11:46:01
xaly,

Вы не пользуетесь UpdatePanel или какой-нибудь другой формой MSAJAX на странице?

Просто вот что говорит MSDN по этому поводу: http://msdn.microsoft.com/ru-ru/library/bb310803.aspx
Zoria
Дата: 31.03.2010 11:48:07
xaly,

а вы это не из updatepanel ли вызываете?
Zoria
Дата: 31.03.2010 11:49:42
Зритель с попкорном 5,

опоздала:)
xaly
Дата: 02.04.2010 08:48:17
Да это кнопка на UpdatePanel , но если вытащить ее от туда такая же ошибка.
Я нашла временный выход, Response.Redirect(@".\Reports\Rep_.xls);