How To: Set the filename for a handler

Skip Navigation LinksIrocon > Blog > 2008 > March, 2008 > March 21, 2008 > How To: Set the filename for a handler

How To: Set the filename for a handler

If you create a handler that allows your users to download/view files. When they save the file the browser attempts to save with the filename and extension of the handler.

Assuming the name of your handler was "Image.ashx" and in your handler you send an image (maybe resized) to the client. If the user attempts to save that image, it will be saved as "Image.ashx", unless you do one of the following:

Response.AddHeader("Content-Disposition", "filename=FileName.ext")

Response.AddHeader("Content-Disposition", "attachment; filename=FileName.ext")

Response.AddHeader("Content-Disposition", "inline; filename=FileName.ext")

Last Updated:Thursday, September 02, 2010By:alfero#

Would you like to comment?

Sign in with your OpenID. If you do not know what OpenID is, find out.