Thursday, 23 May 2013

How to Play .swf file in ASP.NET


How to Play .swf file in ASP.NET


ntroduction
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
        { }
    }
} 

No comments:

Post a Comment