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..Thanks

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);
            }

Dani AI

Generated

The original server-side attempt from was close, and correctly pointed at browser/plugin behavior as the root cause — many browsers will render or hand off well-known types instead of offering "Save As." The most reliable approaches are either to ask the browser to treat the resource as a download (client-side where supported) or to serve it from the server in a way that unambiguously marks it as a download; a mix of both plus a few deployment checks gives the best result.

A simple client-side option (works in modern browsers, subject to cross-origin limits) is the HTML5 download attribute:

<a href="/files/animation.swf" download>Save animation.swf</a>

This avoids server-side header fiddling for same-origin links and is the easiest fix where applicable.

For server-side ASP.NET scenarios a concise, robust pattern is to return a file result that sets a download filename (ASP.NET MVC example):

public ActionResult Download(string name)
{
    var path = Server.MapPath("~/files/" + name);
    return File(path, "application/octet-stream", Path.GetFileName(path));
}

For WebForms or handlers, prefer streaming methods that avoid large memory use (TransmitFile / streaming) and ensure the response includes a download filename and a correct content length. Also quote filenames to handle spaces and non-ASCII safely.

Diagnostics and cautions: inspect the actual response headers (browser devtools or curl) to see what the client receives; check for IIS modules, compression, proxies or CDNs that might rewrite headers; verify the physical path with Server.MapPath and guard against path-traversal. Given that Flash/SWF has been widely deprecated and many browsers block or ignore SWF, packaging the asset (for example, ZIP) is often the most future-proof way to deliver a downloadable copy.

I changed content-type to "application/X-unknown" and it worked for me..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.