views:

63

answers:

1

Error is something like that : alt text

Can't load Items.aspx from 192.168.0.172

And a text is Can't open this web-site. It can't be found. Try later

code :

   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();

Trouble with this file is only for Internet Explorer (works on opera / firefox ... )

And so it works for HTML with no

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

this string

How to avoid this error on IE ?

+1  A: 

Try like this:

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();
tpeczek
the trouble was on SSL ) but that also helped >_< thank you
nCdy