Sending a file from memory to the client

  • Thread starter Thread starter John Owens
  • Start date Start date
J

John Owens

Currently I use Response (below) but it feels a little hacky. Is there
anyway to do this using a nice little Framework class :-)

Response.Clear();

Response.AddHeader("Content-Disposition", "attachment;
filename=Letter.blah");

Response.AddHeader("Content-Length", msOutFileData.Length.ToString());

Response.ContentType = "application/vnd.msword";

Response.BinaryWrite( msOutFileData.GetBuffer() );

Response.Flush();



Response.Redirect( "" );
 
Hi,


no AFAIK, what is wrong with Response?


I would change the Redirect at the end by a Response.End(), other than that
all looks ok

cheers,
 
I thought it might have been wrapped in a nice class.

I also I'm having problems as its not asking for SaveAs. It displays a
dialog box that only asks for Open and Save.

Any idea what causes this as I have tried multiple different Response setups
below is one:

Response.Buffer = true;

Response.ContentType = "application/msword";

Response.AddHeader( "Content-Disposition", "attachment;");

Response.AddHeader( "Content-Length", msOutFileData.Length.ToString());
 
hi,

I think this is the default way, it's cause you have checked the "always ask
before open this kind of file checkbox "

I do it in almost the same way:
Response.AddHeader("Content-Disposition", "attachment;
filename=\""+targetname + "\"");

The only different is that I suggest a filename of the downloaded file.


cheers,
 
Thanks.

Yea, I have tried using a filename. It still won't give me the option to
change it.

Don't worry, I've made it inline (so it opens in the browser) and this
behaviour is acceptable.
 
I'm having another problem where it places junk at the end of the file
whenever I save. Any ideas what might cause that.
 
Hi,


no , no idea

Check the part where you create/fill the stream.

John Owens said:
I'm having another problem where it places junk at the end of the file
whenever I save. Any ideas what might cause that.


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top