Introduction
In this article I will show how to play .swf file in ASP.Net. This is very beneficial for any web developer who want to play any swf file in his/her project.
Implementation
Create page named play_video.aspx . Palce datalist control at this page. You can see it in the HTML code.here I’m using templatefields for bind the datalist.
As per my project, first we add a folder in root directory.the folder are,
Video for storing .swf files.
After uploading the file it store in the video folder
HTML code for play_video.aspx page
<asp:DataList ID="DataList1" runat="server" RepeatColumns="1" Height="550px" Width="700px">
<ItemTemplate>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"
width="600" height="500">
<%-- in the value below line give the path of the folder in which you are storing the .swf file& bind the datalist with the colum name of the database with eval function --%>
<param name="movie" value='video/<%#Eval("videos")%>' />
<param name="quality" value="high" />
<%-- in the src below line give the path of the folder in which you are storing the .swf file--%>
<embed src='video/<%#Eval("videos")%>' quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" width="700px" height="550px"
</embed>
</object>
C# code for play_video.aspx page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Data.Sql;
using System.Drawing;
public partial class videos : System.Web.UI.Page
{
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
//open connection
con.ConnectionString = ConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
try
{
con.Open();
if (Page.IsPostBack == false)
{
bind_datalist();
}
}
catch
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
}
}
private void bind_datalist()
{
// //It will display the data from your specified table and bind the //datalist with the video. You can use sql query accoring to your requirement
SqlDataAdapter adp = new SqlDataAdapter(@" select top(1) video from your table", con);
DataSet ds = new DataSet();
try
{
adp.Fill(ds);
adp.Dispose();
DataList1.DataSource = ds;
DataList1.DataBind();
}
catch
{ }
}
}
Conclusion
Through this article, you have learned how we can play .swf file in our project.
Dear friend,
ReplyDeleteGo through this video to better understand http://youtu.be/2PJIKnoAoV8
In this video i have explained clearly how to add flash...........
It is very simple in one line code...........................
DeleteGo through this video to better understand http://youtu.be/2PJIKnoAoV8
In this video i have explained clearly how to add flash...........
Dear Friend,
ReplyDeleteIts a very nice explanation. I followed your instructions to load the swf file. But i am not successful. Can you please tell whats wrong in the below code? I am getting movie not loaded messages.
object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"
width="980" height="634"
param name="movie" value="video/D:\Articulate\story.swf"
param name="quality" value="high"
embed src="video/D:\Articulate\story.swf" width="”980" height="634" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" wmode="transparent"
Thank you
Suresh Katari