ASP.NET - how to upload and play vedio in gridview in asp.net

Asked By mani on 22-Mar-12 02:07 AM
how to upload and play vedio in gridview in asp.net
Web Star replied to mani on 22-Mar-12 02:13 AM
The best way is you upload video and show the play button in girdview only when the user click on play than that video will be play at a time either on that page of in popup window what is your choice.
For upload video you just use input control with File type as follows
http://www.aspheute.com/english/20000802.asp 

and use window media play to play video in aspx page as follows
http://www.codeproject.com/Tips/202410/Play-Video-files-in-Web-sites.aspx 

hope this helps you
dipa ahuja replied to mani on 22-Mar-12 02:58 AM
you have two choices to store the data
 
1. just store the name of the video file (nvarchar)
2. Store the actual video inside the table (byte)
 
 
With nvarchar dataType to store just name of file
 
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
 try
 {
   string FolderPathToSave = Server.MapPath("~/videos");
  //Save Image in Images Folder
  FileUpload1.SaveAs(FolderPathToSave + @"\" + FileUpload1.FileName);
   Status.Text = "File name: " +
   
   //Save ImageURL in Database
  string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  SqlConnection connection = new SqlConnection(conn);
   connection.Open();
   SqlCommand comm = new SqlCommand("Insert into Photos (iname,url) values (@iname,@url)", connection);
   comm.Parameters.AddWithValue("iname", "photo1");
   comm.Parameters.AddWithValue("url", Path.GetFileName(FileUpload1.PostedFile.FileName));
   comm.ExecuteNonQuery();
   connection.Close();
  }
 catch (Exception ex)
 {
   Status.Text = "ERROR: " + ex.Message.ToString();
 }
}
Withe byte dataType:
 
 private void BtnSave_Click(object sender, EventArgs e)
 {
   try
   {
   byte[] video;
  string fileName = FileUpload1.PostedFile.FileName;
  FileStream fs = new FileStream(fileName, FileMode.Open);
   BinaryReader reader = new BinaryReader(fs);
   video= reader.ReadBytes((int)fs.Length);
   fs.Close();
  string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  SqlConnection connection = new SqlConnection(conn);
   connection.Open();
   SqlCommand comm = new SqlCommand("Insert into table1 (iname,url) values (@iname,@url)", connection);
   comm.Parameters.AddWithValue("iname", "photo1");
   comm.Parameters.AddWithValue("url", video);
   comm.ExecuteNonQuery();
   connection.Close();
 
  }
   catch (Exception ex)
   {
   Response.Write(ex.Message.ToString());
   }
 }
 
Now to display video you have control in codeplex:
 
You can download Video control for asp.net from :
 
<http://videoshow.codeplex.com/>
 
Right Click on the toolBox and choose "Add Tab"
 
and in that new tab again right click and choose - > "choose item"
 
Now one dialogbox will be appear..
 
from that click on browse Button and add the dll of videoCotnrol..
 
and just drag n drop video control :
 
<ASPNetVideo:WindowsMedia ID="WindowsMedia1" runat="server"
    VideoURL="~/DSCN3995.AVI">
   </ASPNetVideo:WindowsMedia>
  
 
Hope this will help you !