creating a csv file for download inside page callback

  • Thread starter Thread starter bbdobuddy
  • Start date Start date
B

bbdobuddy

Hi,

I have a callback that is being called in which I need to create a csv file
that the user can download.

I have the string created correctly but the download prompt dialog box is
not appearing

Here is the last piece of code that should do the download

strFileName = Session("SourceLayer").ToString().Replace(" ",
"_") + DateTime.Now.Year.ToString() + month + day + ".csv"

Response.AddHeader("Content-disposition", "attachment;
filename=" + strFileName)
Response.ContentType = "text/plain"
Response.Write(csvText)
Response.Flush()
Response.End()


Any help would be appreciated
 
Hi,

It is again a while ago that I did this, bus as far as I remember me you
need if you want to download something to set your file on the server and
give the user the link to that using that text control with the option
"File" or just use the a linklabel.

Cor
 
bbdobuddy said:
Here is the last piece of code that should do the download
[...]

I just looked at some of my own code that does what you're trying to do, and
the only differences I can spot are:

- my code also provides a name in the ContentType:

Response.ContentType = "text/plain; name=""filename.txt"""

(actually my code isn't using text/plain as its mime type but I don't see
why that should result in different behaviour).

- my code performs a Response.BinaryWrite instead of Response.Write, as it's
sending binary data instead of text. Again I don't see why that would cause
different behaviour, though.

So try adding the name to the ContentType and see if that makes any
difference..?
 
Back
Top