Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Please give me correct coding for video upload and view to save in database also
Posted 28-Nov-12 23:38pm
Edited 29-Nov-12 9:13am
v2
Comments
Krunal R at 29-Nov-12 5:49am
   
What have you tried ?? Where are you stuck ?? Where's your code ??
shalinibharani at 29-Nov-12 5:56am
   
Video Uploader Control for SQL Server from user code project i get this link but its not working
shalinibharani at 29-Nov-12 5:59am
   
please give me working code ......... that link is not working.
SRamPrabhu at 9-Apr-13 7:46am
   
your stored procedure code wrong
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Refer this Article..
Save MP3 Audio Files to database and display in ASPNet GridView[^]
in place of audio player Use Window media player embed code and pass video url saved in database to play video files.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

To Upload and save Video url in database
 
Sql queries-
create table videos(video_name varchar(200),videosong_loc varchar(500))
create procedure video_upload
@video_name varchar(200),
@video_loc varchar(500)
as
insert into videos values(@video_name,@video_loc)
select * from videos
create procedure Show_video
as
select * from videos
select * from mp3songs
 

 
For aspx(drag and drop fileupload control on page)-
 
<table class="style1">
            <tr>
                <td colspan="2">
                    <asp:FileUpload ID="FileUpload1" runat="server" />
                </td>
            </tr>
            <tr>
                <td class="style2">
                    <asp:Label ID="Label1" runat="server" Text="Video song name"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtvideoname" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td>
 
                </td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td>
                 <asp:Button ID="btnInvoke" runat="server" onclick="btnInvoke_Click" Text="Upload" />
                </td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td>
                    <asp:Label ID="Label2" runat="server"></asp:Label>
                </td>
            </tr>
        </table>
 

For CS(Create one folder name "Video" in the directory)-
    prote
cted void btnInvoke_Click(object sender, EventArgs e)
 
    {
        
        string name = FileUpload1.PostedFile.FileName;
        string ext = System.IO.Path.GetExtension(this.FileUpload1.PostedFile.FileName);
        if (FileUpload1.PostedFile.ContentLength == 0)
        {
 
            Label1.Text = "Cannot upload zero length file";
        }
 

 

 

        if (ext == ".wmv"||ext==".flv")
        {
            DateTime dt = DateTime.Now;
            string tme = dt.ToLongTimeString();
            string[] t = tme.Split(':');
 
            string y = "";
            foreach (string x in t)
            {
                y += x;
            }
 
            string aa = y + "_" + name;
            string location = Server.MapPath(" ") + "\\videos\\" + aa;
            FileUpload1.PostedFile.SaveAs(location);
            string loc = aa;
            //Session["location1"] = loc;
            SqlConnection sqlconn = new SqlConnection("server=.\\sqlexpress;database=db;integrated security=true;");
            SqlCommand sqlcomm = new SqlCommand("video_upload", sqlconn);
            sqlcomm.CommandType = CommandType.StoredProcedure;
            sqlcomm.Parameters.Add("@video_name", SqlDbType.VarChar, 200).Value = txtvideoname.Text;
            sqlcomm.Parameters.Add("@video_loc", SqlDbType.VarChar, 500).Value = loc;
            sqlconn.Open();
            sqlcomm.ExecuteNonQuery();
            sqlconn.Close();
 
            Label2.Text = "Video Song uploaded Successfully";
        }
        else
        {
            Label2.Text = "please choose .wmv file";
        }
    }
  Permalink  
Comments
Marcus Kramer at 29-Nov-12 15:14pm
   
Please don't just drop full code answers to OP's who don't show they have made any effort to solve the problem themselves. What you are doing is earning them marks in school that they don't deserve.
Surendra0x2 at 30-Nov-12 0:13am
   
Oh Sorry Sir
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

And To Show uploaded Video-
 
Now Drag and Drop on Gridview on page-
 
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown">
        CellPadding="20" ForeColor="#333333" GridLines="None">
        <rowstyle backcolor="#F7F6F3" forecolor="#333333" />
    <columns>
    <asp:boundfield datafield="video_name" headertext="Video Name" />
    <asp:templatefield headertext="Play Video">
    <itemtemplate>
    <a href="playvideo.aspx?id=<%# Eval(" videosong_loc=") %>">Play Video</a>
    
    </itemtemplate>
    
    </asp:templatefield>
    
    </columns>
        <footerstyle backcolor="#5D7B9D" font-bold="True" forecolor="White" />
        <pagerstyle backcolor="#284775" forecolor="White" horizontalalign="Center">
            Width="500px" />
        <selectedrowstyle backcolor="#E2DED6" font-bold="True" forecolor="#333333" />
        <headerstyle backcolor="#5D7B9D" font-bold="True" forecolor="White" />
        <editrowstyle backcolor="#999999" />
        <alternatingrowstyle backcolor="White" forecolor="#284775" />
    </pagerstyle></asp:gridview>
 

and on Page_load(CS Code)
 
 
SqlConnection sqlconn = new SqlConnection("server=.\\sqlexpress;database=db;Integrated Security=True");
            SqlCommand sqlcomm = new SqlCommand("Show_video", sqlconn);
sqlcomm.CommandType = CommandType.StoredProcedure;
            sqlconn.Open();
            SqlDataReader dr = sqlcomm.ExecuteReader();
            if (dr.HasRows)
            {
                GridView1.DataSource = dr;
                GridView1.DataBind();
                sqlconn.Close();
                dr.Close();
            }
 
and in gridview u'll See a Play Button when u'll Click on Play then it will Redirect u on play.aspx(Create one page play.aspx and place one label control on it).
 
  <asp:label id="Label1" runat="server" text="Label"></asp:label>
 
 
and on CS(on Page_load)-
 
 
string play = Request.QueryString["id"];
            string strSQL = "select * from videos where videosong_loc='" + play + "'";
            SqlConnection sconn = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=db;Integrated Security=True");
 
            SqlCommand scomm = new SqlCommand(strSQL, sconn);
            sconn.Open();
            SqlDataReader sreader = scomm.ExecuteReader();
            if (sreader.Read())
            {
 
                string Str = "videos\\" + sreader[1].ToString();
                string text = "<embed src="" + Str + "" height="300" width="500"><noembed>Sorry, your browser doesn't support the embedding of multimedia.</noembed></embed>";
                //Response.Write(text);
                Label1.Text = text;
                sreader.Close();
                sconn.Close();
 
 
Follow these codes and use your Mind Shalini Ji Big Grin | :-D
Happy Coding Smile | :)
  Permalink  
v3
Comments
Surendra0x2 at 29-Nov-12 13:34pm
   
Here is working Demo-
http://surendrakumarverma.com/Video.aspx
khaleel md at 22-Dec-12 5:10am
   
hi sir ...
am using above code, getting the blank window player in output but not with video.... will u pls send me the solution..
Surendra0x2 at 22-Dec-12 10:45am
   
use this tag to play video file in window media player..take one label control then. follow this(Label1.Text='object code in single line without line break')
cs page-
Label1.Text='<object id='mediaPlayer' width='320' height='285'>
classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'
codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
<param name='fileName' value='video url' />
<param name='animationatStart' value='true' />
<param name='transparentatStart' value='true' />
<param name='autoStart' value='true' />
<param name='showControls' value='true' />
<param name='loop' value='false' />
</object>'
 
and paste one video in ur solution explorer.
then play if this wroks then u can upload and save video url to database then u can pass url to window media player embed code.
let me know if this wrks.
 
refer this video too-
http://www.youtube.com/watch?v=FQxzGuPzs1U
khaleel md at 28-Dec-12 7:58am
   
Dear sir ...Thnx 4 the response
am getting errors while creating <param>tag in cs file as Error 8 Too many characters in character literal
 
here is my code which i am using
____________________________________
 
in...Default.aspx...
____________________________________
<body>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td colspan="2">
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" Text="Video song name">
</td>
<td>
<asp:TextBox ID="txtvideoname" runat="server">
</td>
</tr>
<tr>
<td class="style2">
 </td>
<td>

</td>
</tr>
<tr>
<td class="style2">
 </td>
<td>
<asp:Button ID="btnInvoke" runat="server" onclick="btnInvoke_Click" Text="Upload"
style="height: 26px" />
</td>
</tr>
<tr>
<td class="style2">
 </td>
<td>
<asp:Label ID="Label2" runat="server">
</td>
</tr>
</table>



<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px"
CellPadding="4" GridLines="Horizontal" Height="218px" Width="284px">


<asp:boundfield datafield="video_name" headertext="Video Name" />
<asp:templatefield headertext="Play Video">

Play Video








<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />

<asp:label id="Label3" runat="server" text="Label">
<div>

</div>
</form>
</body>
__________________________
khaleel md at 31-Dec-12 4:20am
   
in .Default.aspx.cs...
__________________________
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;
public partial class _Default : System.Web.UI.Page
{
SqlConnection sqlconn = new SqlConnection("Data Source=SYSTEM7;Initial Catalog=master;User ID=sa;Password=Code");
protected void Page_Load(object sender, EventArgs e)
{
// SqlConnection sqlconn = new SqlConnection("Data Source=SYSTEM15;Initial Catalog=master;Integrated Security=True");
SqlCommand sqlcomm = new SqlCommand("Show_video", sqlconn);
//SqlCommand sqlcomm = new SqlCommand("select videosong_loc from videos", sqlconn);
sqlcomm.CommandType = CommandType.StoredProcedure;
sqlconn.Open();
SqlDataReader dr = sqlcomm.ExecuteReader();
if (dr.HasRows)
{
GridView1.DataSource = dr;
GridView1.DataBind();
sqlconn.Close();
dr.Close();
}

}
protected void btnInvoke_Click(object sender, EventArgs e)
{
 
string name = FileUpload1.PostedFile.FileName;
string ext = System.IO.Path.GetExtension(this.FileUpload1.PostedFile.FileName);
if (FileUpload1.PostedFile.ContentLength == 0)
{
 
Label1.Text = "Cannot upload zero length file";
}
 

 

 

if (ext == ".wmv" || ext == ".flv" || ext == ".avi"||ext==".mp4" || ext==".MPEG-4" || ext==".wma ")
{
DateTime dt = DateTime.Now;
string tme = dt.ToLongTimeString();
string[] t = tme.Split(':');
 
string y = "";
foreach (string x in t)
{
y += x;
}
 
string aa = y + "_" + name;
string location = Server.MapPath(" ") + "\\videos\\" + aa;
FileUpload1.PostedFile.SaveAs(location);
string loc = aa;
//Session["location1"] = loc;
//SqlConnection sqlconn = new SqlConnection("Data Source=SYSTEM7;Initial Catalog=master;User ID=sa;Password=Code");
SqlCommand sqlcomm = new SqlCommand("video_upload", sqlconn);
sqlcomm.CommandType = CommandType.StoredProcedure;
sqlcomm.Parameters.Add("@video_name", SqlDbType.VarChar, 200).Value = txtvideoname.Text;
sqlcomm.Parameters.Add("@videosong_loc", SqlDbType.VarChar, 500).Value = loc;
sqlconn.Open();
sqlcomm.ExecuteNonQuery();
sqlconn.Close();
 
Label2.Text = "Video Song uploaded Successfully";
}
else
{
Label2.Text = "please choose .wmv file";
}
}
khaleel md at 31-Dec-12 4:33am
   
_________________
In Play.aspx.cs
_________________
protected void Page_Load(object sender, EventArgs e)
{
 
string play = Request.QueryString["ID"];
string strSQL = "select * from videos where video_name='Play'";
SqlConnection sconn = new SqlConnection("Data Source=SYSTEM7;Initial Catalog=master;User ID=sa;Password=Code");

SqlCommand scomm = new SqlCommand(strSQL, sconn);
sconn.Open();
SqlDataReader sreader = scomm.ExecuteReader();
if (sreader.Read())
{

string Str = "videos\\" + sreader[1].ToString();
//string text = "<embed src=" + Str + " height=300 width=500>Sorry, your browser doesn't support the embedding of multimedia.</embed>";
//Response.Write(text);
//Label1.Text="'<object id='mediaPlayer' width='320' height='285'> classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701' standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'">
// <param name='fileName' value='video url' />
// <param name='animationatStart' value='true' />
// <param name='transparentatStart' value='true' />
// <param name='autoStart' value='true' />
// <param name='showControls' value='true' />
// <param name='loop' value='false' />
// </object>'"
sreader.Close();
sconn.Close();
 
}

}
khaleel md at 31-Dec-12 4:35am
   
play.aspx
__________
<body>
<form id="form1" runat="server"><%--<object><embed src=" "+ Str + height="300" width="500">
Sorry, your browser doesnot support the embedding of multimedia.
</embed></object>;--%>
<object id="mediaplayer" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701" standby="loading microsoft windows media player components..." type="application/x-oleobject" width="320" height="310">
<param name="filename" value="videos/">
<param name="animationatstart" value="true"/>
<param name="transparentatstart" value="true"/>
<param name="autostart" value="true"/>
<param name="showcontrols" value="true"/>
<param name="ShowStatusBar" value="true"/>
<param name="windowlessvideo" value="true"/>
<embed src="videos/" autostart="true" showcontrols="true" showstatusbar="1" bgcolor="white" width="3200" height="3100">
</embed>

</object>
<div>
</div>
</form>
<asp:label id="Label1" runat="server" text="Label">
</body>
Surendra0x2 at 13-Jan-13 13:00pm
   
use this to save song to database and play
 
refer this Link i added source code-
http://www.mediafire.com/file/cc43uccvd274epp/Save_Binary_image_and_Mp3_and_Show_image_and_Play_Song_inside_gridview.rar

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 646
1 OriginalGriff 385
2 CPallini 240
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,795
1 Sergey Alexandrovich Kryukov 5,158
2 CPallini 4,740
3 George Jonsson 3,167
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 22 Dec 2012
Copyright © CodeProject, 1999-2014
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