ndraycott 0 Newbie Poster

Hi
I am trying to upload and convert video files then retrieve the filepath. I successfully managed to upload and save the filepath, but I am trying to add the converting functionality. The code I have so far is below.

Thanks in advance

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConfirm.Click

            If IsPostBack Then
            Dim path As String = Server.MapPath("~/UploadedVideos/")
                Dim fileOK As Boolean = False
                If FileUploadVideo.HasFile Then

                    Dim fileExtension As String
                    fileExtension = System.IO.Path. _
                        GetExtension(FileUploadVideo.FileName).ToLower()
                    Dim allowedExtensions As String() = _
                        {".mov", ".wmv", ".avi", ".vob", ".mp4"}
                    For i As Integer = 0 To allowedExtensions.Length - 1
                        If fileExtension = allowedExtensions(i) Then
                            fileOK = True
'this is where I want the converter to work
                        postedfilename = FileUploadVideo.PostedFile.FileName
                        SavePath = AppDomain.CurrentDomain.BaseDirectory + "~/UploadedVideos/"
                        Dim NewFName As String = postedfilename
                        NewFName = NewFName.Substring(NewFName.LastIndexOf("\") + 1, NewFName.Length - NewFName.LastIndexOf(".")) + "." + NewFName.Substring(NewFName.LastIndexOf(".") + 1)
                        Filenamewithpath = SavePath + NewFName

                        'Save The file
                        FileUploadVideo.PostedFile.SaveAs(Filenamewithpath)

                        'Start Converting
                        Dim inputfile As String, outputfile As String, filargs As String
                        Dim withoutext As String

                        'Get the file name without Extension
                        withoutext = SavePath(NewFName)

                        'Input file path of uploaded image
                        inputfile = SavePath + NewFName

                        'output file format in swf
                        outputfile = SavePath + "SWF\" + withoutext + ".swf"

                        'file orguments for FFMEPG
                        filargs = "-i " + inputfile + " -ar 22050 " + outputfile

                        Dim spath As String
                        spath = Server.MapPath(".")
                        Dim proc As Process
                        proc = New Process()
                        proc.StartInfo.FileName = spath + "\ffmpeg\ffmpeg.exe"
                        proc.StartInfo.Arguments = filargs
                        proc.StartInfo.UseShellExecute = False
                        proc.StartInfo.CreateNoWindow = False
                        proc.StartInfo.RedirectStandardOutput = False
                        Try


                            proc.Start()
                        Catch ex As Exception
                            Response.Write(ex.Message)
                        End Try
                        proc.WaitForExit()
                        proc.Close()



                    End If
                    Next
                    If fileOK Then
                        Using Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
                            Try
                                Conn.Open()
                                Dim FilePath = path & FileUploadVideo.FileName
                                'Here you can fire your insert statement in filepath value u can pass directly that value
                                Const SQL As String = "INSERT INTO [Video] ([VideoName], [CourseNo], [ModuleNo], [DateUploaded], [VideoUrl], [Keywords]) VALUES (@VideoName, @CourseNo, @ModuleNo, @DateUploaded, @VideoUrl, @Keywords)"
                                Dim cmd As New SqlCommand(SQL, Conn)
                                cmd.Parameters.AddWithValue("@VideoName", txtVideoName.Text.Trim())
                                cmd.Parameters.AddWithValue("@CourseNo", cboCourse.SelectedValue())
                                cmd.Parameters.AddWithValue("@ModuleNo", cboModule.SelectedValue())
                                cmd.Parameters.AddWithValue("@DateUploaded", Date.Now)
                                cmd.Parameters.AddWithValue("@VideoUrl", FilePath)
                                cmd.Parameters.AddWithValue("@Keywords", txtKeywords.Text.Trim())
                                FileUploadVideo.PostedFile.SaveAs(path & _
                                     FileUploadVideo.FileName)


                                lblError.Text = "File uploaded!"
                                cmd.ExecuteNonQuery()
                                Conn.Close()
                            Catch ex As Exception
                                lblError.Text = "File could not be uploaded." & ex.Message
                            End Try
                        End Using
                    Else
                        lblError.Text = "Cannot accept files of this type."
                    End If
                End If
            End If


        End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.