EXPORT TO .CSV WITHOUT CREATING A FILE ON THE SERVER!!!

  • Thread starter Thread starter LUIS FAJARDO
  • Start date Start date
L

LUIS FAJARDO

I want to know if there is a way to export a DataGrid
(ASP.NET) without actually having to create a file on the
server. Something like to be able to export an Stream
that is saved as a file on the client side.


Thanks
 
Hi Luis,

To send a file to the browser without creating a file on the server, you
can try to put what you are going to send into a MemoryStream, and then use
Response.BinaryWrite to write it to the client side.

HTH

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "LUIS FAJARDO" <[email protected]>
| Sender: "LUIS FAJARDO" <[email protected]>
| Subject: EXPORT TO .CSV WITHOUT CREATING A FILE ON THE SERVER!!!
| Date: Wed, 1 Oct 2003 20:16:46 -0700
| Lines: 7
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOIk5yRPc0rjTITSNK57bcjcks4GQ==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:188478
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I want to know if there is a way to export a DataGrid
| (ASP.NET) without actually having to create a file on the
| server. Something like to be able to export an Stream
| that is saved as a file on the client side.
|
|
| Thanks
|
 
Hi,
You could write custom HTTP handler (implement the IHttpHandler interface)
for the .CSV file extension. In such handler, you could retrieve data,
convert the data to CSV, set appropriate ContentType for response and write
your data away (using Output or OutputStream). Also, you could use the
"Content-Disposition" header to override the file name on the client's side.

The client's browser will execute request by URL like
http://mysite.com/data/12345.csv, your handler will send appropriate
response, the browser will detect the type of content and will ask the user
to open or save the file.
 
One approach would be to emit (Response.Write) CrLf delimited rows with Tab
delimited columns like so...

Col1 Col2 Col3
1 2 3
456 789 123

Then, set the Response.COntentType = "application/msexcel" (not sure if
this is exactly right, but search the registry for .xls and see what the
MIME type is)

That's one way.

Of course, it requires that your client either have Excel or an Excel viewer
on their machine to handle the content.

Michael Earls
 
Back
Top