Monday, March 26, 2012

Set file name returned from ASP.NET page by URL

Hi!
I have an .aspx page which returns an image. This page takes some GET
parameters, so URL looks like this:
http://localhost/page.aspx?id=1234
Now, when the user click this link, I want that his browser would receive
picture with some good looking name, like image1.jpg.
How to do this within ASP.NET code ?..

--
Pawe
www.DATAX.plWrite an HTTPHandler. Using the Handler, you can make a request for an image
file and get back whatever the handler returns. For example,

http://localhost/image1.jpg?id=1234

would return an image named "image1.jpg" - which could be anything you
generate via your Handler.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"pawel" <pawel.zarzycki@.interia.pl> wrote in message
news:#1SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> Hi!
> I have an .aspx page which returns an image. This page takes some GET
> parameters, so URL looks like this:
> http://localhost/page.aspx?id=1234
> Now, when the user click this link, I want that his browser would receive
> picture with some good looking name, like image1.jpg.
> How to do this within ASP.NET code ?..
> --
> Pawe
> www.DATAX.pl
Thanks for the answer.
Can you shortly tell me what exactly is that HTTPHandler ?.. I cant find
such topic in MSDN.
Paul

"Kevin Spencer" <kevin@.takempis.com> wrote in message
news:%23PRm1$B7DHA.2764@.TK2MSFTNGP09.phx.gbl...
> Write an HTTPHandler. Using the Handler, you can make a request for an
image
> file and get back whatever the handler returns. For example,
> http://localhost/image1.jpg?id=1234
> would return an image named "image1.jpg" - which could be anything you
> generate via your Handler.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
> "pawel" <pawel.zarzycki@.interia.pl> wrote in message
> news:#1SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> > Hi!
> > I have an .aspx page which returns an image. This page takes some GET
> > parameters, so URL looks like this:
> > http://localhost/page.aspx?id=1234
> > Now, when the user click this link, I want that his browser would
receive
> > picture with some good looking name, like image1.jpg.
> > How to do this within ASP.NET code ?..
> > --
> > Pawe
> > www.DATAX.pl
You might try something like this:

Response.Clear();
Response.AddHeader("Content-Disposition","inline;filename=image1.jpg");
Response.WriteFile("myfile.jpg");

Here's more info:
http://msdn.microsoft.com/library/d...tefiletopic.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"pawel" <pawel.zarzycki@.interia.pl> wrote in message
news:%231SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> Hi!
> I have an .aspx page which returns an image. This page takes some GET
> parameters, so URL looks like this:
> http://localhost/page.aspx?id=1234
> Now, when the user click this link, I want that his browser would receive
> picture with some good looking name, like image1.jpg.
> How to do this within ASP.NET code ?..
> --
> Pawe
> www.DATAX.pl
Sure. An HttpHandler is a class that handles HTTP requests. In ASP.Net a
Page class, for example, is the default HttpHandler for files with a .aspx
extension. You can map different file extensions to different HttpHandlers
in ASP.Net. What happens is, when the web server receives a request for a
file, it looks in its configuration to find out whether a special
HttpHandler has been designated for that file extension. ASP.Net provides
the HttpHandler class to extend the functionality of ASP.net to be able to
handle requests for other file types (extensions). In IIS, you make ASP.Net
the HttpHandler for the type of file that you desire, and use the web.config
file for your web to identify what DLL (Class Library) is used to handle
specific file extensions.

The HttpHandler is a clsss that handles the request. It has access to the
same HttpContext (Request, Response, Cookies, Session, Application, Server,
etc) that the Page class does.

For more detailed information, see:

http://msdn.microsoft.com/library/d...ttphandlers.asp

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"pawel" <pawel.zarzycki@.interia.pl> wrote in message
news:uLuTwUC7DHA.1052@.TK2MSFTNGP12.phx.gbl...
> Thanks for the answer.
> Can you shortly tell me what exactly is that HTTPHandler ?.. I cant find
> such topic in MSDN.
> Paul
> "Kevin Spencer" <kevin@.takempis.com> wrote in message
> news:%23PRm1$B7DHA.2764@.TK2MSFTNGP09.phx.gbl...
> > Write an HTTPHandler. Using the Handler, you can make a request for an
> image
> > file and get back whatever the handler returns. For example,
> > http://localhost/image1.jpg?id=1234
> > would return an image named "image1.jpg" - which could be anything you
> > generate via your Handler.
> > --
> > HTH,
> > Kevin Spencer
> > .Net Developer
> > Microsoft MVP
> > Big things are made up
> > of lots of little things.
> > "pawel" <pawel.zarzycki@.interia.pl> wrote in message
> > news:#1SMC4B7DHA.1040@.TK2MSFTNGP10.phx.gbl...
> > > Hi!
> > > I have an .aspx page which returns an image. This page takes some GET
> > > parameters, so URL looks like this:
> > > http://localhost/page.aspx?id=1234
> > > Now, when the user click this link, I want that his browser would
> receive
> > > picture with some good looking name, like image1.jpg.
> > > How to do this within ASP.NET code ?..
> > > > --
> > > Pawe
> > > www.DATAX.pl
> >

0 comments:

Post a Comment