Click here to Skip to main content
13,191,618 members (63,365 online)
Rate this:
Please Sign up or sign in to vote.
See more:
how to play a video file in with C# page link file save in database.
please replay ...
Posted 12-Jan-12 9:03am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Please have a look at the links provided:

Display videos in ASP.Net 2.0[^]
Streaming Media[^]

Slightly out of subject but these will also help you:
How do i use to display video from bytes in sql database[^]
Play video file from database through handler[^]

Good luck,
thatraja 12-Jan-12 15:53pm
2nd link is my favorite one, 5!
Orcun Iyigun 12-Jan-12 17:56pm
Thanks thatraja :)
NandaKumer 13-Jan-12 1:16am
good links
Orcun Iyigun 13-Jan-12 2:28am
thank you Nanda.
Rajesh Anuhya 13-Jan-12 2:12am
Good answer , have my +5
Orcun Iyigun 13-Jan-12 2:29am
thank you Rajesh!
Tech Code Freak 6-Feb-12 6:32am
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

If you have save path of video in database then you can play as

take a datalist and bind it with video url.
<asp:datalist id="DataList1" runat="server" repeatdirection="Horizontal" xmlns:asp="#unknown">
	RepeatColumns="4" BackColor="White" BorderColor="#CC9966" BorderStyle="Solid" 
	 BorderWidth="1px" CellPadding="4" GridLines="Both"      
        onitemcommand="DataList1_ItemCommand1" Width="99%" 
           <asp:imagebutton id="Image1" runat="server" height="120px" width="180px" imageurl="~/temp/thumb.jpg" commandname="select" commandargument="<%#Eval("url") %>" /><br />
           <asp:linkbutton id="LinkButton2" runat="server" forecolor="Blue" onclick="<%#Eval("url") %>" commandname="select" commandargument="<%#Eval("url") %>"> <%#Eval("Video_Name") %></asp:linkbutton><br />
        <asp:sqldatasource id="SqlDataSource1" runat="server" xmlns:asp="#unknown">
        ConnectionString="<%$ ConnectionStrings:cnn %>" 
        SelectCommand="SELECT [Video_Name], [url] FROM [electronicmedia] order by sno desc ">

and use embed tag to get player
<embed id='embed1' runat="server" name='mediaPlayer' type='application/x-mplayer2' pluginspage=''  displaysize='4' autosize='-1' bgcolor='darkblue' showcontrols='true' showtracker='-1' showdisplay='0' showstatusbar='-1' videoborder3d='-1' width='500' height='405'  designtimesp='5311' loop='false'>

on datalist itemcommand
protected void DataList1_ItemCommand1(object source, DataListCommandEventArgs e)
           if (e.CommandName == "select")
               string path = e.CommandArgument.ToString().Trim();
               embed1.Attributes.Add("src", e.CommandArgument.ToString().Trim());
       catch (Exception ex)
Chandrakant_Bhanu 18-Feb-12 3:47am
pls mail me this project i need this project for may current project actuly
i am confuse on this line this.modal1.Show(); this line genret error pls help me my contact email id is
Uma Shankar Patel 18-Feb-12 3:56am
modal1 is a Ajax ModalPoup extender to pop up player..
you can see Ajax ModalPoup extender on google
you do not need this, you can put embed code on panel,div.
Chandrakant_Bhanu 18-Feb-12 4:12am
which video format u use for this project
VyasRavi6776 23-Sep-12 8:37am
Hi..i have tried a lot...but video is not playing ..
i m showing my code here..


<embed id='embed1' runat="server" name='mediaPlayer' type='application/x-mplayer2' pluginspage='' displaysize='4' autosize='-1' bgcolor='darkblue' showcontrols='true' showtracker='-1' showdisplay='0' showstatusbar='-1' videoborder3d='-1' width='500' height='405' designtimesp='5311' loop='false'>



protected void Page_Load(object sender, EventArgs e)

embed1.Attributes.Add("src", "~/VIDEO/Ekla.mp4");


So please Do the needfull
Uma Shankar Patel 24-Sep-12 1:17am
when you run this,A player should show.I think problem is video not playing in player.
Right click on player.see properties=>see location
check if you get the correct location....
if it is wrong change it with src attribute
Willem Geerts 18-Mar-13 6:43am
I don't see anything of the video in firefox ? In chrome and internet expl. well
Is this normal?
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

try this

<object type="video/x-ms-wmv" data="video\video.mpeg" width="420" height="340">
   <param name="url" value="video\video.mpeg"/>
   <param name="src" value="video\video.mpeg" />
   <param name="autostart" value="true" />
   <param name="sound" value="false" />
   <param name="controller" value="true" />
Rate this: bad
Please Sign up or sign in to vote.

Solution 6

<html xmlns="">
<head  runat="server">
    <form id="form1"  runat="server">
    <table style="width: 400px;" border="0" cellpadding="2" cellspacing="3">
            <td style="width: 150px;" valign="top">
            <td style="width: 200px;" valign="top" align="left">
                <asp:label id="lblMsg" cssclass="tdMessage" text="" runat="server" xmlns:asp="#unknown"></asp:label>
            <td class="tdText" valign="top" align="left">
                <nobr> Select a file</nobr>
            <td style="text-align: left;" valign="top">
                <asp:fileupload id="fUpload" runat="server" width="300px" xmlns:asp="#unknown"></asp:fileupload>
            <td valign="top" align="left">
                <asp:button id="btnUpload" runat="server" text="Upload" onclick="btnUpload_Click" xmlns:asp="#unknown">
            <td valign="top" align="left">
                <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">

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace VideoDemo
    public partial class VDemo : System.Web.UI.Page
        public string swfFileName;
        protected void Page_Load(object sender, EventArgs e)
        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 = "images/" + 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 + "images\\";
Jitendra Kumar Gangwar 20-Mar-12 3:04am
thanks, your code working properly but i want to play .mp4 file in asp net.
jeta6561 24-May-12 0:32am
can you please send me project .. above describe code
210032278 11-Jul-13 21:55pm
i copyed your code exacle as it is but when i debac it says "This webpage is not available" on a browser. What myt be the problem
m.asghari 20-Jul-13 7:33am
why do not play .dat files???
ketan italiya 26-Nov-13 3:13am
superb code,it's working nice,thanks.......
Rate this: bad
Please Sign up or sign in to vote.

Solution 7

        <asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown">
            DataSourceID="SqlDataSource1" BackColor="#CCCCCC" BorderColor="#999999" 
            BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" 
                <asp:templatefield headertext="Welcome Here are few Uploads Done by you!!">
                        <asp:hyperlink id="HyperLink1" runat="server">
                            NavigateUrl='<%# Eval("id", "~/Default5.aspx?id={0}") %>' 
                            Text='<%# "Click Here to Play Video"+ Eval("id") %>' ondatabinding="HyperLink1_DataBinding"></asp:hyperlink>
            <footerstyle backcolor="#CCCCCC" />
            <headerstyle backcolor="Black" font-bold="True" forecolor="White" />
            <pagerstyle backcolor="#CCCCCC" forecolor="Black" horizontalalign="Left" />
            <rowstyle backcolor="White" />
            <selectedrowstyle backcolor="#000099" font-bold="True" forecolor="White" />
            <sortedascendingcellstyle backcolor="#F1F1F1" />
            <sortedascendingheaderstyle backcolor="#808080" />
            <sorteddescendingcellstyle backcolor="#CAC9C9" />
            <sorteddescendingheaderstyle backcolor="#383838" />
        <asp:sqldatasource id="SqlDataSource1" runat="server" xmlns:asp="#unknown">
            ConnectionString="<%$ ConnectionStrings:examConnectionString %>" 
            SelectCommand="SELECT * FROM [video]"></asp:sqldatasource>
        <asp:repeater id="Repeater1" runat="server" xmlns:asp="#unknown">
         <object id="MediaPlayer" width="270" height="270">
            CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"  STANDBY="Loading Windows Media Player components..."
            TYPE="application/x-oleobject"><param name="autoplay" value="true">
            <param name="width" value="270">
            <param name="height" value="270">
            <param name="FileName" value="<%#">></param></param></param></param></object>

Code Behind Will be:

private void bindrepeater()
        if (string.IsNullOrEmpty(Request.QueryString["id"]))
           //do nothing
            SqlCommand cmd = new SqlCommand("select name from video where id=@id", con);
            cmd.Parameters.AddWithValue("@id", Request.QueryString["id"]);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            Repeater1.DataSource = ds;
    public string grtdata()
        SqlCommand cmd = new SqlCommand("select name from video", con);
        SqlDataReader dr = cmd.ExecuteReader();

        string filename = dr[0].ToString();
        string path = "~/Videos/";//Name of folder where you will save your videos
        string opath = Server.MapPath(path);
        return opath;
    protected void HyperLink1_DataBinding(object sender, EventArgs e)

[edit]code block added[/edit]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171017.2 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100