Не удается отправить файл из веб-приложения в Internet Explorer - PullRequest
1 голос
/ 27 мая 2010

Ошибка примерно такая: альтернативный текст http://i020.radikal.ru/1005/76/e94bd2f2c61f.jpg

Не удается загрузить Items.aspx с 192.168.0.172

И текст не может открыть этот веб-сайт. Это не может быть найдено. Попробуй позже

код:

   HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpContext.Current.Response.Charset = System.Text.Encoding.Unicode.EncodingName;
    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Unicode;
    HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
    HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
    HttpContext.Current.Response.AddHeader(
         "content-disposition", string.Format(
            "attachment; filename={0}",fileName));

....

        table.RenderControl(htw);
        HttpContext.Current.Response.Write(sw.ToString());
        HttpContext.Current.Response.End();

Проблема с этим файлом есть только для Internet Explorer (работает на Opera / Firefox ...)

И так работает для HTML без

HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";

эта строка

Как избежать этой ошибки в IE?

1 Ответ

1 голос
/ 27 мая 2010

Попробуй так:

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);     
HttpContext.Current.Response.Charset = System.Text.Encoding.Unicode.EncodingName;     
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Unicode;
HttpContext.Current.Response.AddHeader("Content-Type", "application/ms-excel");
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", outputFileName));
HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
...
table.RenderControl(htw);       
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...