On Tue, 10 May 2005 12:50:06 -0500, david
<da***@discussions.microsoft.com> wrote:
Is it the static way for displaying images? Can i dynamically display
.jpg
files in this way? For example, I convert images into .jpg format and
display
them on the web page in runtime on request.
David
"Brock Allen" wrote:
<img> tags require an independant request tot he server for the JPG
data,
so you can't interlace JPG and HTML data in the response back to the
browser.
You'll have to setup a secondary page or IHttpHandler to serve those up.
Or just set the <img src="images/foo.fpg"> path and let the normal
webserver
serve up those static files.
-Brock
DevelopMentor
http://staff.develop.com/ballen
> Can I use WriteFile methods? It seems that it does not work. For
> example, the following code only dispay one figure.
> Response.WriteFile("images/image002.jpg") Response.Write("<br><p>")
> Response.WriteFile("c") Response.Write("<br><p>")
>
> Any help?
>
> Thanks
>
> David
>
You want to create an aspx to handle displaying an image, have it do the
WriteFile() using a QueryString argument passed in.
Let's call this page foo.aspx and the querystring arg is imageUrl. Then
in my main page (where I want to show the image) I would do
<img src="foo.aspx?imageUrl=images%2Fimage002.jpg" >...
<img src="foo.aspx?imageUrl=iamges%2Fimage003.jpg" >...
note I URL encoded the / to %2F. Now in foo.aspx, you want to remove all
code, whitespace, html, everything from the .aspx file; then in the
..aspx.vb or .aspx.cs do all the work of displaying the image via
WriteFile() (write the file with url = imageUrl). You can also Google
around a little bit for a thorough example, you'll want to set the
content-type to the image type you are using in foo.aspx as well as some
miscellaneous response settings.
Why remove everything from .aspx? You can only have 1 MIME type per
response. Previously (as pointed out the other poster) you had
intermingled image and html data. Doesn't work. And if anything is in
your .aspx (other than directives), it will be compiled as a Literal
(HTML) and spit out with the response, once again mixing MIME types
inadvertently.
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET