Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
New Feature: Community Sites:
Create your own .NET community website and start earning from Google AdSense !
It's Free !
|
Upload Videos in a ASP.NET page
|
The following code sample is a ASP.NET page in .aspx and followed by the code behind c# file, that,altogether, shows a way to enable users to upload videos.
<td style="width: 100px"> <a href="vediodisplay.aspx?vname=<%#Eval("video_path") %>&cap=<%#Eval("caption") %>"><asp:Image ID="Image1" runat="server" Height="100px" Width="100px" ImageUrl='<%# Eval("video_pic") %>' /></a></td> <td style="width: 100px"> <asp:ImageButton ID="ImageButton2" runat="server" Height="20px" ImageUrl="~/images/edit.jpg" Width="24px" CommandName="edit"/><br /> <br /> <asp:ImageButton ID="ImageButton1" runat="server" OnClientClick="return confirm('are u sure u want to delete')" CommandName="delete" Height="24px" ImageUrl="~/images/delete.jpg" /></td> </tr> <tr> <td style="width: 100px; height: 18px;"> <asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small" Text='<%# Eval("caption") %>' Width="87px" ForeColor="DarkGreen"></asp:Label></td> </tr>
The code behind page follows that manages PageLoad event and has a method videobind that is the core of the entire code.
/////////////code behind//////////////// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { videobind(); } }
public void videobind() { DataList1.DataSource = vob.getvideos(); DataList1.DataBind(); //for (int i = 0; i < DataList1.Items.Count; i++) //{ // ImageButton img = (ImageButton)DataList1.Items[i].FindControl("ImageButton1"); // img.Attributes.Add("OnClick", "return confirm('Are you sure want to delete?')");
//} } if (this.FileUpload1.HasFile) { string userflname = ".\\upload" + "\\"; //".\\userfolder\\" + ufdname + "\\";
string cliptype = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName); if (cliptype == ".mpeg") { string clipname = FileUpload1.PostedFile.FileName; string name = clipname.Substring(clipname.LastIndexOf(@"\")); string name1 = name.Remove(name.IndexOf(@"."));
string name2 = name1.Substring(1); string newclipname = (string)Session.SessionID + "_" + name2 + 1; string uploadpath = Request.MapPath(".\\upload\\"); FileUpload1.PostedFile.SaveAs(uploadpath + newclipname);
string apppath = Request.PhysicalApplicationPath; string inputpath = apppath + "upload\\" + newclipname; string ss = apppath + "upload\\" + newclipname; string outputpath = apppath + userflname + newclipname + ".flv";
string fileargs = " -i \"" + inputpath + "\" \"" + outputpath + "\"";
System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = apppath + "ffmpeg\\ffmpeg.exe"; proc.StartInfo.Arguments = fileargs; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = false; proc.StartInfo.RedirectStandardOutput = false; proc.Start(); proc.WaitForExit();
string inputpath1 = apppath + userflname + newclipname + ".flv"; string outputpath1 = apppath + userflname + "%d" + newclipname + ".jpg";
string fileargs1 = " -i \"" + inputpath1 + "\" -an -ss 00:00:04 -an -r 1 -vframes 1 -y \"" + outputpath1 + "\""; System.Diagnostics.Process proc1 = new System.Diagnostics.Process(); proc1.StartInfo.FileName = apppath + "ffmpeg\\ffmpeg.exe"; proc1.StartInfo.Arguments = fileargs1; proc1.StartInfo.UseShellExecute = false; proc1.StartInfo.CreateNoWindow = false; proc1.StartInfo.RedirectStandardOutput = false; proc1.Start(); proc1.WaitForExit(); File.Delete(ss);
string dt = System.DateTime.Now.ToShortDateString(); string movie1 = newclipname + ".flv"; string img1 = "1" + newclipname + ".jpg"; string s = userflname + movie1; string s1 = userflname + img1;
string str11 = Request.PhysicalApplicationPath; System.IO.FileStream theFLV = System.IO.File.OpenRead(str11 + s);
string vidpath = userflname + newclipname + ".flv"; string vidpic = userflname + img1;
vob.getvideo_path = vidpath; vob.getvideo_pic = vidpic; vob.getcaption = TextBox1.Text; vob.getwhen = DateTime.Now; vob.videoinsert(); //cmd = ob.dbcmd("insert_vid_gallery"); //cmd.Parameters.Add("@title", SqlDbType.VarChar, 500).Value = TextBox1.Text; //cmd.Parameters.Add("@vid_path", SqlDbType.VarChar, 500).Value = vidpath; //cmd.Parameters.Add("posted_by", SqlDbType.Int).Value = uid; //cmd.Parameters.Add("vid_pic", SqlDbType.VarChar, 500).Value = vidpic; //cmd.ExecuteNonQuery(); //Page.RegisterStartupScript("chk", "<script>alert('Successfully uploaded.......')</script>"); //TextBox1.Text = ""; } else if (cliptype == ".flv" || cliptype == ".swf") { string clipname = FileUpload1.PostedFile.FileName; string name = clipname.Substring(clipname.LastIndexOf(@"\")); string name1 = name.Remove(name.IndexOf(@"."));
string name2 = name1.Substring(1); string newclipname = (string)Session.SessionID + "_" + name2 + 1; string uploadpath = Request.MapPath(".\\upload\\"); FileUpload1.PostedFile.SaveAs(uploadpath + newclipname);
string apppath = Request.PhysicalApplicationPath; string inputpath = apppath + "upload\\" + newclipname; string ss = apppath + "upload\\" + newclipname; string outputpath = apppath + userflname + newclipname + ".flv";
string fileargs = " -i \"" + inputpath + "\" \"" + outputpath + "\"";
System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = apppath + "ffmpeg\\ffmpeg.exe"; proc.StartInfo.Arguments = fileargs; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = false; proc.StartInfo.RedirectStandardOutput = false; proc.Start(); proc.WaitForExit();
string inputpath1 = apppath + userflname + newclipname + ".flv"; string outputpath1 = apppath + userflname + "%d" + newclipname + ".jpg";
string fileargs1 = " -i \"" + inputpath1 + "\" -an -ss 00:00:04 -an -r 1 -vframes 1 -y \"" + outputpath1 + "\""; System.Diagnostics.Process proc1 = new System.Diagnostics.Process(); proc1.StartInfo.FileName = apppath + "ffmpeg\\ffmpeg.exe"; proc1.StartInfo.Arguments = fileargs1; proc1.StartInfo.UseShellExecute = false; proc1.StartInfo.CreateNoWindow = false; proc1.StartInfo.RedirectStandardOutput = false; proc1.Start(); proc1.WaitForExit(); File.Delete(ss);
string dt = System.DateTime.Now.ToShortDateString(); string movie1 = newclipname + ".flv"; string img1 = "1" + newclipname + ".jpg"; string s = userflname + movie1; string s1 = userflname + img1;
string str11 = Request.PhysicalApplicationPath; System.IO.FileStream theFLV = System.IO.File.OpenRead(str11 + s); string vidpath = userflname + newclipname + ".flv"; string vidpic = userflname + img1;
//vob.getuser_id = 18; //sesion vob.getvideo_path = vidpath; vob.getvideo_pic = vidpic; vob.getcaption = TextBox1.Text; vob.getwhen = DateTime.Now; vob.videoinsert(); //cmd = ob.dbcmd("insert_vid_gallery"); //cmd.Parameters.Add("@title", SqlDbType.VarChar, 500).Value = TextBox1.Text; //cmd.Parameters.Add("@vid_path", SqlDbType.VarChar, 500).Value = vidpath; //cmd.Parameters.Add("posted_by", SqlDbType.Int).Value = uid; //cmd.Parameters.Add("vid_pic", SqlDbType.VarChar, 500).Value = vidpic; //cmd.ExecuteNonQuery(); //Page.RegisterStartupScript("chk", "<script>alert('Successfully uploaded.......')</script>"); } TextBox1.Text = ""; } else { Page.RegisterStartupScript("vob", "<script>alert('please give an appropriate file type')</script>"); } videobind();
|
Responses
|
| Author: jingyeu 07 Dec 2008 | Member Level: Bronze Points : 1 | hi, can you give more details to this video upload code, there are errors showing, also like what is the vob? and what other buttons that we need to create? the 'if' condition is just appear in the middle of the coding, thanks !
| | Author: Abhinav Misra 07 Dec 2008 | Member Level: Silver Points : 1 | very good sir but it is good if u can ex plane it it will good for all new and experience programmer
|
|