Click here to Skip to main content
15,891,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii i m uploading video using this code now i want to play this on Asp page.
plzz tell me any idea or code..Thnxx..!!
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
using System.Web;

public partial class video1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    byte[] buffer;
    protected void Button1_Click(object sender, EventArgs e)
    {
        {
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
byte[] MediaBytes = new byte[FileUpload1.PostedFile.InputStream.Length];
if (FileUpload1.HasFile && FileUpload1.PostedFile != null
&& FileUpload1.PostedFile.FileName != "")
{
HttpPostedFile file = FileUpload1.PostedFile;
buffer = new byte[file.ContentLength];
int bytesReaded = file.InputStream.Read(buffer, 0, FileUpload1.PostedFile.ContentLength);
if (bytesReaded > 0)
{
try
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=DEEPAK-PC\\SQLEXPRESS;Initial Catalog=NewCrackers;User ID=sa;Password=sasa";
conn.Open();
SqlCommand cmd = new SqlCommand
("INSERT INTO Videos (Video, Video_Name, Video_Size) VALUES (@video, @videoName, @videoSize)", conn);
cmd.Parameters.Add("@video", SqlDbType.VarBinary, buffer.Length).Value = buffer;
cmd.Parameters.Add("@videoName", SqlDbType.NVarChar).Value = FileUpload1.FileName;
cmd.Parameters.Add("@videoSize", SqlDbType.BigInt).Value = file.ContentLength;
using (conn)
{
cmd.ExecuteNonQuery();
Label1.Text = " uploaded ";
conn.Close();
}
}
catch (Exception ex)
{
Label1.Text = ex.Message.ToString();
}
}
}
else
{
Label1.Text = "Choose a valid video file";
}
}
}
}
Posted

 
Share this answer
 
Comments
Christian Graus 24-Jan-14 3:49am    
This only works in Internet Explorer and is a bad answer now that HTML5 exists.
Download Flash control/silverlight and add it in your toolbox.
Then assign path to the control.

Download flashControl Here[^]and silverlightHere[^]

For Flash player:
C#
Flash1.MovieURL = "Path ";


Silverlight:
C#
MediaPlayer1.MediaSource = "Path ";
 
Share this answer
 
v2
If you're targeting new browsers, you don't need a plug in.

This[^] is a library that works with the HTML5 video player, but you don't need it, the underlying tags they are using is more than enough to play video on any modern browser.
 
Share this answer
 

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