Tuesday, January 22, 2008

Upload Videos in ASP.Net

protected void btnUpload_Click(object sender, EventArgs e)

{

string Venu = Request.QueryString["Venu"];

if (!( UVideo.PostedFile.ContentType == "video/x-ms-wmv" || UVideo.PostedFile.ContentType == "video/mpg" || UVideo.PostedFile.ContentType == "video/mpeg" || UVideo.PostedFile.ContentType == "video/divx" || UVideo.PostedFile.ContentType == "video/div" || UVideo.PostedFile.ContentType == "video/tix" || UVideo.PostedFile.ContentType == "video/mp4" || UVideo.PostedFile.ContentType == "video/qt" || UVideo.PostedFile.ContentType == "video/mov" || UVideo.PostedFile.ContentType == "video/avi" || UVideo.PostedFile.ContentType == "video/mp3" || UVideo.PostedFile.ContentType == "video/mpa" || UVideo.PostedFile.ContentType == "video/mpe" || UVideo.PostedFile.ContentType == "video/mp2" || UVideo.PostedFile.ContentType == "video/m1v" ))

{

pnlRight.Visible = false;

pnlWrong.Visible = true;

lblError.Text = "Video Extension Not Match";

return;

}

string file = System.IO.Path.GetFileName( System.IO.Path.GetExtension( UVideo.PostedFile.FileName ));

string loc = Server.MapPath("..")+ @"\"+ Venu + @"\Videos\" + ViewState["Id"].ToString() + file;

UVideo.PostedFile.SaveAs(loc);

SqlConnection sqlcon;

SqlCommand sqlcmd;

sqlcon = new SqlConnection ( System.Configuration.ConfigurationManager.AppSettings ["ConStr"] );

try

{

sqlcon.Open();

sqlcmd = new SqlCommand("updt_Video", sqlcon);

sqlcmd.CommandType = CommandType.StoredProcedure;

sqlcmd.Parameters.AddWithValue("@Vid", ViewState["Id"]);

sqlcmd.Parameters.AddWithValue("@VTitle", txtTitle.Text);

sqlcmd.Parameters.AddWithValue("@VPath", ViewState["Id"] + file);

sqlcmd.ExecuteNonQuery();

sqlcon.Close();

pnlRight.Visible = true;

pnlWrong.Visible = false;

lblRight.Text = "Video Uploaded Sucessfully";

}

catch (Exception ex)

{

sqlcon.Close();

Response.Write(ex.ToString());

}

finally

{

sqlcon.Close();

}

}



-
ShriKrishna Bhardwaj , With ASP.Net, SQL Server, Javascript

No comments: