Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Right-click "Save picture As.." saves aspx file instead of jpeg 1

Status
Not open for further replies.

christheprogrammer

Programmer
Jul 10, 2000
258
CA
Hi again everyone,
I am using the following code to send a jpeg out thru HTTP:

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "image/jpeg"
Response.WriteFile(relativeJpegPath)
Response.Flush()
Response.Close()

where relativeJpegPath is the path including the jpeg filename.

and the jpeg appears nicely on the web page. However, when I right click the jpeg and select save as, the default filename for saving is Species.aspx which is the aspx page in which the code above appears. Indeed, when I save the file, it is asp.net code as opposed to the jpeg image I expect. What's up with this?

Thanks a bunch - tgif Life is like a box of chocolates, sweet
 
Chris why don't you just add the picture using the HTML image type? I probably am not understanding what you are trying to do. That'l do donkey, that'l do
[bravo]
 
Hey Zarcom,
I am redirecting some different types (jpeg,gif,png,pdf,ai) all from one page, so I can't just embed an image in a new html page. I am setting the content type, etc. and sending the files thru the response object. Unfortunately I cannot do the Save as thing for the picture types (jpeg, gif, png). Damn
Any ideas out there? Life is like a box of chocolates, sweet
 
How about a button that redirects to the file?
 
Thanks Alcar, but I tried that and get the same problem. You are talking about this right?

Response.Redirect("C:\temp\somefile.jpeg")

Same problem - but I erred before when I said the ASPX file was being saved. What is really saved is the HTML file which was generated by ASP.NET. Strange thing, and I NEED to figure this out!!

Thanks guys Life is like a box of chocolates, sweet
 
Are you saving the image or file at all anywhere??
 
Yes, The file exists on the server, and I am using the following code (inside an on_click button event) to send it to the browser:

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "image/JPEG"
Response.WriteFile("C:\temp\somepic.jpeg")
Response.Flush()
Response.Close()


And when the user clicks the button the image appears nicely in the browser as expected (on an otherwise blank page). But when the user right-clicks the picture and then select "Save Picture As..", the save dialog comes up with the name of the source ASP.NET page that the file was sent from (the page with the button that was pressed). Renaming and Saving the file, then opening it locally, the user finds that it is the HTML page which ASP.NET generated to show the ASPX page, not the picture that was expected! I hope that is a bit more clear... Life is like a box of chocolates, sweet
 
This solution is more complicated but could you create a new HTML file with the <image> tag in it and then send it to the response object?

process:
create file
create html
attach file to html &quot;<image> tag&quot;
view html

 
I had a very similar problem to this. If there is any html in the page that is displaying the picture it will try to save the whole page. If you want to save an image you will need to make sure that no HTML is being sent to the browser. I was getting caught up because a line of HTML was being read even though it was not being displayed on the page. The second line that VS creates on the page that reads <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;> was my problem after I removed this I could save the image just fine. Hope this helps with your situation.


Ctau
 
Thanks guys.

Ctau: I didn't really understand your solution. I don't see how you can tell ASP.NET to not include that line when making up its HTML from your ASP.NET page...

Alcar: I had thought of doing it that way, and I've been left with no choice. I was trying to avoid coding in yet another dynamically generated page... But I found it works fine, so I'm going with that method. Thanks again guys! Life is like a box of chocolates, sweet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top