473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Prompt "SaveAs" Dialog on Image click like for applications, .zip etc

Coldfire
289 100+
Hello,

The issue is: I have a webpage that displays image in img tag while taking its src from a remote url ( dynamically). Now, my client want this functionality to ask for "Save at any location" routine when someone clicks on the image so that user can avoid right-click saveas.

Platform: xp/asp.net2.0/web-application

PLz help asap
May 22 '07 #1
3 1589
Plater
7,872 Expert 4TB
Well if you have an onclick handler for the image (which is tricky because the aspx page validator will always give you a warning saying "this tag does not support that feature" or something)

if you want the picture to prompt for download you will probably have to do some middleman work. Your code will have to make a request for the picture on the remote server THEN send it back to your client (in response to their click) with an extra header that declares it to be downloaded.

Something like:
Expand|Select|Wrap|Line Numbers
  1. string DefaultFileName="Whatever.jpg";//or whatever
  2. string myContentType="image/jpg"; //or whatever
  3. Response.Clear();
  4. Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
  5. Response.ContentType = myContentType;
  6. Response.AddHeader("content-disposition", "attachment; filename=" + DefaultFileName);
  7. Response.Write(cbuff, 0, cbuff.Length);
  8. //where cbuff is a char[] containing your image data
  9. Response.End();
  10.  
May 22 '07 #2
Coldfire
289 100+
thanks that helped...but I am still struggling!

Well if you have an onclick handler for the image (which is tricky because the aspx page validator will always give you a warning saying "this tag does not support that feature" or something)

if you want the picture to prompt for download you will probably have to do some middleman work. Your code will have to make a request for the picture on the remote server THEN send it back to your client (in response to their click) with an extra header that declares it to be downloaded.

Something like:
Expand|Select|Wrap|Line Numbers
  1. string DefaultFileName="Whatever.jpg";//or whatever
  2. string myContentType="image/jpg"; //or whatever
  3. Response.Clear();
  4. Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
  5. Response.ContentType = myContentType;
  6. Response.AddHeader("content-disposition", "attachment; filename=" + DefaultFileName);
  7. Response.Write(cbuff, 0, cbuff.Length);
  8. //where cbuff is a char[] containing your image data
  9. Response.End();
  10.  
May 22 '07 #3
Plater
7,872 Expert 4TB
Well break it down into steps, first you need to get the image clickable AND have the click be caught by your server code.

I would suggest making a new aspx page called like ImageDownloader.aspx
And make that page have its sole job is to perform those sneaky manuvers.

So for an image like this:
[html]
<img id="myimage" src="http://www.google.com/intl/en_ALL/images/logo.gif">[/html]
You could have an onclick method that goes to:
Expand|Select|Wrap|Line Numbers
  1. http://mywebsite/ImageDownloader.aspx?url=http://www.google.com/intl/en_ALL/images/logo.gif
  2.  
Then inside your ImageDownloader.aspx file, parse out the URL
Expand|Select|Wrap|Line Numbers
  1. if (Request.Params["url"]!=null)
  2. {
  3.    // validate the string, attempt to fetch the data, then send it back with the code i posted earlier
  4. }
  5. else
  6. {
  7.    // respond back with an error of somesort
  8. }
  9.  
May 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: lir | last post by:
Hi, I am trying to save a fram in a page using the execCommand("saveas") the html is save currectly but I can not save the gif on that page. How can I save the fram with the gif via...
0
by: OutdoorGuy | last post by:
Greetings, I have the code below where I am instantiating Excel and then attempting to the save the new workbook (as "Test.xls"). However, on the line of code that attempts to save the...
0
by: GS | last post by:
why am I getting saveas dialog prompt from the following code Dim doOpt As SHDocVw.OLECMDEXECOPT doOpt = SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER '<<< is this is the one to suppress...
2
by: psanjay | last post by:
Hi, Am unable to open javascript SaveAs dialog box in Firefox browser. Following is the script, <a href="javascript:void(0);" onclick="document.execCommand('SaveAs',false,'*.xyz');">Save this...
4
by: GavReynolds | last post by:
Hi All! I am using Javascript to export some content in a popup (in this case, just 5 simple words) to a text file. This works fine and the user can save the text file. Upon opening the file,...
6
by: mrobinson86 | last post by:
Hey guys, wondered if anybody could help me out with a pretty simple piece of code that has been driving me crazy for the past few days? I am trying to create a client side self sustaining message...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.