I wish to insert an swf files in ASP.Net, how can I do it? What is the code in ASP.Net?

Dani AI

Generated

Short, practical update (years after the original thread): the classic ways you see above — a single embed (as suggested) or the object + param approach (as showed, and as mixed for compatibility) — are how SWFs were embedded in pages. However, Flash Player was retired by Adobe (EOL Dec 31, 2020) and browsers have removed/blocked plugin support, so most public websites can no longer rely on in‑browser SWF playback. (adobe.com)

If you still must host SWF files for internal or archival purposes, do these server-side steps so the file is served correctly from IIS/ASP.NET (clients still able to run it locally or via an emulator):

<configuration>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".swf" />
      <mimeMap fileExtension=".swf" mimeType="application/x-shockwave-flash" />
    </staticContent>
  </system.webServer>
</configuration>

Also, when streaming a SWF from code set the Content-Type and use TransmitFile to avoid buffering large files:

Response.Clear();
Response.ContentType = "application/x-shockwave-flash";
Response.TransmitFile(Server.MapPath("~/media/foo.swf"));
HttpContext.Current.ApplicationInstance.CompleteRequest();

These server settings are the MIME-safe way to serve .swf files from IIS/ASP.NET. (learn.microsoft.com)

For in-page playback on modern browsers consider alternatives instead of relying on the old plugin. Two practical options:

  • Convert the content to HTML5/Canvas/WebAssembly (recommended by Adobe as the long‑term migration path). (adobe.com)

  • Use a Flash emulator like Ruffle to run many SWFs inside modern browsers (include the tiny CDN script and test each file — AS3 support is improving but not perfect). Example include:

    <script src="https://unpkg.com/@ruffle-rs/ruffle"></script>

Test thoroughly; Ruffle’s compatibility varies by ActionScript version. (ruffle.rs)

Practical notes tied to earlier replies: emitting the embed/object HTML from a server control (Label/Literal) — as recommended — still works for static pages, but avoid inserting untrusted input (XSS), set appropriate headers (Content‑Security‑Policy, X‑Content‑Type‑Options: nosniff) and treat this as a temporary, legacy solution while migrating to HTML5 or a supported emulator.

Recommended Answers

All 7 Replies

you can achieve that with single lines of html code :
<embed src="foo.swf" />
you can embed any object using embed tag.

Thanks buddy! How about if I wish to specify the size of the object?

you can specify those settings via tag attributes. like <embed width="59px" and so forth. if you use visual studio, the intellisense will propose you the attribute options when you push the space button after typing the tag.

This is valid XHTML code for inserting swf.

<object type="application/x-shockwave-flash" data="SWFPath" width="SWFWidth" height="SWFHeight">
<param name="movie" value="SWFPath" />
</object>

You can place a label control at the positon displaying swf info. Just set label caption with the swf tag. This way is simple but useful when you want to display swf samples for products for movie trailers on ecommerce webistes.

<OBJECT id="banner" style="WIDTH: 696px; HEIGHT: 192px" codeBase="images/banner.swf" code="images/banner.swf" VIEWASTEXT>
<PARAM NAME="movie" VALUE="images/banner.swf">
<embed src="images/banner.swf" width="696" height="192"> </embed>
</OBJECT>

change the required attributes like source ,width ,height ,,etc
hope ths wil help u,,
reply if it does

Thanks to all of you guys. Its a big help!

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.