Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
1.33/5 (6 votes)
Plz if sm1 can help me out i need code written in the upload button witch helps me to upload a video into databse from an file upload field i'm using VB.net webform design and Sql management studio 2008 R2
please i'm new to these stuff and i needed for my final project so i apreciate any help ......
thanks in advanced
Posted
Updated 4-Apr-12 3:19am
v2
Comments
kroz18 5-Apr-12 4:57am    
If IsPostBack Then
Dim path As String = Server.MapPath("~/UploadedVideos/")
Dim fileOK As Boolean = False
If FileUpload1.HasFile Then
Dim fileExtension As String
fileExtension = System.IO.Path. _
GetExtension(FileUpload1.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
End If
Next
If fileOK Then
Dim Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("projectConnectionString").ConnectionString)

Conn.Open()
Try
Dim FilePath = path & FileUpload1.FileName
'Here you can fire your insert statement in filepath value u can pass directly that value
Dim SQL As String = "INSERT INTO EmpData ( [Video]) VALUES (@VideoUrl)"
Dim cmd As New SqlCommand(SQL, Conn)
cmd.Parameters.Add("@VideoUrl", SqlDbType.NVarChar, 50, FilePath)
FileUpload1.PostedFile.SaveAs(path & _
FileUpload1.FileName)
lblError.Text = "File uploaded!"
cmd.ExecuteNonQuery()
Conn.Close()
Catch ex As Exception
lblError.Text = "File could not be uploaded." & ex.Message
End Try

Else
lblError.Text = "Cannot accept files of this type."
End If
End If
End If


i've saved it into a private sub Upload() to call it from the save button but when i press the button this MSG appears:
The connection was reset
The connection to the server was reset while the page was loading.

dunno where is my mistake plz can anyone help ????

1 solution

 
Share this answer
 
Comments
kroz18 5-Apr-12 4:59am    
thank you for your reply :) i apreciate it and yes it was helpful but i've listed the problem i had so plz if you can help there i'll apreciate it thanks in advanced :)
codeBegin 14-May-12 6:59am    
Good links! 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900