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 !