SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand("insert into Tbl_Videos(VideoName,VideoPath)values(@VideoName,@VideoPath)");
string fileExt = System.IO.Path.GetExtension(FileUpload1.FileName);
if (fileExt == ".avi")
{
try
{
FileUpload1.SaveAs(Server.MapPath("~/video/" +FileUpload1.FileName));
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +"Content type: "+FileUpload1.PostedFile.ContentType;
cmd.Parameters.AddWithValue("@VideoName",FileUpload1.FileName);
cmd.Parameters.AddWithValue("@VideoPath", FileUpload1.FileName);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
}
else
{
Label1.Text = "Only .avi files allowed!";
}
}
问问题
429 次