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/") If FileUploadVideo.HasFile Then If isValidExtension(System.IO.Path.GetExtension(FileUploadVideo.FileName).ToLower()) Then Using Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString) Try Dim FilePath = path & FileUploadVideo.FileName + fileExtension Dim SQL As String = "INSERT INTO [Video] ([VideoName], [CourseNo], [ModuleNo], [VideoUrl]) VALUES (@VideoName, @CourseNo, @ModuleNo, @VideoUrl)" 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("@VideoUrl", FilePath) FileUploadVideo.PostedFile.SaveAs(path & FileUploadVideo.FileName) lblError.Text = "File uploaded!" Conn.Close() Catch ex As Exception lblError.Text = "File could not be uploaded; Error: " + ex.message End Try End Using Else lblError.Text = "Cannot accept files of this type." End If End If End If End Sub Private Function isValidExtension(fileExt As String) As Boolean Dim allowedList As String() = {".mov", ".wmv", ".avi", ".vob", ".mp4"} Return allowedList.Contains(fileExt.ToLower) End Function
cmd.Parameters.AddWithValue("@VideoUrl", FilePath)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)