Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.40/5 (6 votes)
See more:
Please give me correct coding for video upload and view to save in database also
Posted
Updated 29-Nov-12 9:13am
v2
Comments
[no name] 29-Nov-12 5:49am    
What have you tried ?? Where are you stuck ?? Where's your code ??
shalinibharani 29-Nov-12 5:56am    
Video Uploader Control for SQL Server from user code project i get this link but its not working
shalinibharani 29-Nov-12 5:59am    
please give me working code ......... that link is not working.
S Ram Prabhu 9-Apr-13 7:46am    
your stored procedure code wrong

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.
 
Share this answer
 
v2
To Upload and save Video url in database

Sql queries-
SQL
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)-

XML
<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)-
C#
    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";
        }
    }
 
Share this answer
 
Comments
fjdiewornncalwe 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 30-Nov-12 0:13am    
Oh Sorry Sir
And To Show uploaded Video-

Now Drag and Drop on Gridview on page-

ASP.NET
<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)

C#
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.NET
<asp:label id="Label1" runat="server" text="Label"></asp:label>


and on CS(on Page_load)-

C#
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 :D
Happy Coding :)
 
Share this answer
 
v3
Comments
Surendra0x2 29-Nov-12 13:34pm    
Here is working Demo-
http://surendrakumarverma.com/Video.aspx
khaleel md 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 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 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">
<rowstyle backcolor="White" forecolor="#333333">
<columns> <asp:boundfield datafield="video_name" headertext="Video Name" />
<asp:templatefield headertext="Play Video">
<itemtemplate>
Play Video






<footerstyle backcolor="White" forecolor="#333333">
<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 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";
}
}

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900