Thanks for your response Tim,
Yes, the exporting code you provided is standard one and after some further
testing, I think the problem is just caused by the httpheader set by
Response.Cache.SetCacheability(HttpCacheability.NoCache)
I just captured the http messages when setting and not setting the above
"NOCache" option and found that when the http response returned the
Cache-Control: no-cache
header. So we can also reproduce the problem when using the following code:
page_load...
{
Response.CacheControl = "no-cache";
ExportDataGrid(dgSheet,"test.xls");
}
IMO, this should be the clientside browser's behavior against "no-cache"
response with stream content other than the original text/html content. So
would you try avoid setting the CacheAbility or the "Cache-Control" header
to "no-cache" when you'd like to output custom binary file stream?
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Tim_Mac" <
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: Re: File download problem with Response.Cache.SetCacheability
| Date: 19 Oct 2005 04:10:04 -0700
| Organization:
http://groups.google.com
| Lines: 43
| Message-ID: <
[email protected]>
| References: <
[email protected]>
| <
[email protected]>
| NNTP-Posting-Host: 83.141.121.205
| Mime-Version: 1.0
| Content-Type: text/plain; charset="iso-8859-1"
| X-Trace: posting.google.com 1129720209 11894 127.0.0.1 (19 Oct 2005
11:10:09 GMT)
| X-Complaints-To: (e-mail address removed)
| NNTP-Posting-Date: Wed, 19 Oct 2005 11:10:09 +0000 (UTC)
| In-Reply-To: <
[email protected]>
| User-Agent: G2/0.2
| X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.7.10) Gecko/20050716 Firefox/1.0.6,gzip(gfe),gzip(gfe)
| Complaints-To: (e-mail address removed)
| Injection-Info: g47g2000cwa.googlegroups.com; posting-host=83.141.121.205;
| posting-account=UaxKfw0AAAA4oMLJHydK195yIv1avAma
| Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fastwebnet.it!tiscali!ne
wsfeed1.ip.tiscali.net!news.glorb.com!postnews.google.com!g47g2000cwa.google
groups.com!not-for-mail
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:132397
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| hi Steven,
| thanks for the reply. yes i suppose you're right it could be the
| export code, but when i added the SetCacheability, the export routine
| broke, when i took it away, the export worked...
|
| here is the export code, fairly standard i think:
|
| /// <summary>
| /// Write a dataset to the HttpResponse as an excel file.
| /// </summary>
| public static void ExportDataGrid(DataGrid dg, string filename)
| {
| HttpResponse response = HttpContext.Current.Response;
|
| // clean up the response.object
| response.Clear();
| response.Charset = "";
| response.ContentEncoding = Encoding.UTF8;
| response.Charset = "";
| response.AddHeader("Content-Disposition", "attachment; filename=\"" +
| filename + "\"");
|
| // get the text of the rendered datagrid
| string dgText;
| using (StringWriter sw = new StringWriter())
| {
| using (HtmlTextWriter htw = new HtmlTextWriter(sw))
| {
| // instantiate a datagrid
| dg.RenderControl(htw);
| dgText = sw.ToString();
| }
| }
| response.ContentType = "application/vnd.ms-excel";
| response.Write(dgText);
| response.End();
| }
|
| i'll be interested to hear any insight you may have into this
| behaviour.
| thanks
| tim
|
|