Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys

I am trying to use below code to show a save dialog box when a link with .swf file is clicked, But the problem is that its not working.
Can anyone share the code to show a save dialoge box when a link is clicked with .swf file extention. Please see the below code, I am calling it on htmlanchor click event. Let me know if there are any other soltions..

try
{
    HtmlAnchor anchor = (HtmlAnchor)sender;
    System.IO.FileInfo targetfile = new System.IO.FileInfo(anchor.HRef);

    if (targetfile.Exists)
    {
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + targetfile.Name);
        Response.AddHeader("Content-Length", targetfile.Length.ToString());
        Response.ContentType = "application/x-shockwave-flash";
        Response.WriteFile(targetfile.FullName);
    }
}
catch (Exception ex)
{
    LogException(ex);
}
Posted
Updated 26-May-10 4:07am
v3

I'm glad you found a solution. By the way, this may be a security risk:
wajans wrote:
System.IO.FileInfo targetfile = new System.IO.FileInfo(anchor.HRef);

If somebody hacks an HTTP request, they can potentially send back an arbitrary file name (which would give them access to pretty much any file on your website, such as the web.config).
 
Share this answer
 
You could try:

Response.ContentType "application/octet-stream"


Good luck!
 
Share this answer
 
We can't help you if you don't tell us more than "it's not working".

WHAT isn't working? Did you try running the code under the debugger?
 
Share this answer
 
Thanks for all your replies. I resolved it by changing this line: Response.ContentType = "application/x-shockwave-flash";
to
Response.ContentType = "application/x-Unknown";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900