Click here to Skip to main content
Click here to Skip to main content

How To Play SWF File In Asp.Net

, 28 Oct 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
This article demostrates how to play an swf (flash) file in


This article demonstrates how to play an swf file (flash) in  

There is some additional requirement that browser must have plug-in installed in order make this work.

In this project you need to upload a swf file and then click on the uplaod file to run the uploaded file.

Using the code

It is very simple to create and to paly swf file.

Following are the steps to create and play swf file. 

  • Step 1. Open Microsoft Visual Studio. Create a web site and named it PlaySwfFile.
  • Step 2. Create an .aspx file and named it PlaySwfFile.aspx. 
  • Step 3. Design the form that looks like this. 
  • swfImage.gif 
  • Step 4. Or copy and paste the code in  PlaySwfFile.aspx file inside the <body> tag 
   <form id="form1" runat="server">
        <table width="410px">
                <td align="center"  valign="top">
                    <table border="0" cellpadding="2" cellspacing="3" style="width: 400px;">
                            <td valign="top" style="width: 150px">
                            <td align="left" valign="top" style="width: 200px">
                                <asp:Label ID="lblMsg" CssClass="tdMessage"  Text ="" runat="server"></asp:Label></td>
                            <td valign="top" class="tdText" align="left">
                              <nobr> Select a file</nobr> </td>
                            <td valign="top" style="text-align: left">
                                <asp:FileUpload ID="fUpload" runat="server" Width="300px" /></td>
                            <td align="left" valign="top">
                                <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" /></td>
                            <td align="left" valign="top">
                                <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=",0,19,0"
                                    width="200" height="100">
                                    <param name="movie" value="<% =swfFileName%>" />
                                    <param name="quality" value="high" />
                                    <embed src="<% =swfFileName%>" quality="high" pluginspage=""
                                        type="application/x-shockwave-flash" width="200" height="100"></embed>

 //  Now Add a namespace System.IO; to the   PlaySwfFile.aspx.cs file 

// Declare a variable above page_load() method  

  public string swfFileName = "";

 // Now double click on the upload button and ddd the following code below   

protected void btnUpload_Click(object sender, EventArgs e)
        if (fUpload.FileContent.Length >0 && IsVaildFile())
            string Path = GetUplaodImagePhysicalPath();
            DirectoryInfo dirUploadImage = new DirectoryInfo(Path);
            if (dirUploadImage.Exists == false)
            string fileUrl = Path + fUpload.PostedFile.FileName;
            swfFileName = "image/" + fUpload.PostedFile.FileName;
    private bool IsVaildFile()
        string swfExt = System.IO.Path.GetExtension(fUpload.PostedFile.FileName);
        switch (swfExt)
            case ".swf":
                return true;
                    lblMsg.Text = "Please select only swf file.";
                    return false;

    string GetUplaodImagePhysicalPath()
        return System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "image\\";


Now run the project and upoad a swf file and click on upload button. you will get the result.

Points to Remember 

In the .cs page you will get a public variable named swfFileName. This is the variable which is used in the aspx page to assign as the source of <object>. 

Here <object>  serves as swf player.

In aspx file the public variable swfFileName is accessed as <% =swfFileName%>  



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


About the Author

Najmul Hoda
Software Developer (Senior) Birla Soft
India India
Najmul Hoda is a Master of Computer Application.
He has worked with .Net technologies in web development and has been programming since 2007.
He is very comfortable in various languages,RDBMS & platforms from C# to VB.NET with Access & MS SQLServer
from Javascript,AJAX to ASP.NET.
Besides programming he loves playing mouth organ, guitar, listening to music,singing, bike riding & cricket.

Najmul's Articles
You can get my all article at

Comments and Discussions

QuestionMovie not loaded message when pointing embed src to "d:\abc\story.swf" [modified] PinmemberSURESH_KATARI7-Jul-14 21:20 
QuestionHow to convert and implement this code in VB9 Pinmemberrkear8917-Jan-13 4:04 
Questionthanks PinmemberRaj kumar Rajbhar6-Nov-12 19:03 
GeneralMy vote of 5 PinmemberRenju Vinod19-Aug-12 23:36 
Questionthnks Pinmemberabhay09810-Feb-12 20:20 
BugSwf not playing in ie PinmemberD.R.Chakravarthy19-Oct-11 0:59 
QuestionHow To Play SWF File In Asp.Net - Error: "The given path's format is not supported." PinmemberWijesinghe4-Aug-11 21:10 
AnswerRe: How To Play SWF File In Asp.Net - Error: "The given path's format is not supported." Pinmembermohmed216-Feb-12 22:35 
AnswerRe: How To Play SWF File In Asp.Net - Error: "The given path's format is not supported." PinmemberAndrewTMyers31-Jul-12 6:35 
GeneralRe: How To Play SWF File In Asp.Net - Error: "The given path's format is not supported." PinmemberAndrewTMyers31-Jul-12 6:39 
QuestionNotSupported Exception was unhandled by user code Pinmemberakshaychawla11-May-11 0:28 
AnswerRe: NotSupported Exception was unhandled by user code PinmemberWijesinghe4-Aug-11 21:07 
Generalquestion Pinmembershivshankar pal26-Mar-11 4:04 
Generalnice and simple code Pinmemberripalsoni14-Mar-11 10:09 
Questiona question Pinmemberahatamirad9-Nov-10 21:15 
GeneralMy vote of 5 Pinmemberdeepak chaudhari snk14-Oct-10 1:03 
GeneralNice answer Pinmemberwalsing30-Jul-10 5:33 
GeneralRe:How to play SWF file in Pinmemberyadav awadhesh24-Mar-09 19:17 
Generalnice one again PinmemberVuyiswa Maseko13-Feb-09 3:20 
Generalcustom logo Pinmemberkris4413-Jul-11 5:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 29 Oct 2008
Article Copyright 2008 by Najmul Hoda
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid