Imports System.Data.SqlClient
Imports EnterpriseDT.Net.Ftp
Imports System.Data
Imports System.Diagnostics
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Call save()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Response.Redirect("home.aspx?data=")
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click, TextBox1.Load
TextBox1.Text = Request.QueryString("id")
End Sub
Private Sub save()
Dim connection As SqlConnection = Nothing
Dim fileok1 As Boolean = False
'check the file to make sure it is of the required type
Dim fileExtension1 As String
fileExtension1 = System.IO.Path. _
GetExtension(PicUpload.FileName).ToLower()
'declare the allowed extentions
Dim allowedExtensionsimg As String() = _
{".bmp", ".jpg", ".psd", ".gif", ".jpeg"}
'loop to check the extention type
For i As Integer = 0 To allowedExtensionsimg.Length - 1
If fileExtension1 = allowedExtensionsimg(i) Then
fileok1 = True
End If
Next
Dim img As FileUpload = CType(PicUpload, FileUpload)
Dim imgByte As Byte() = Nothing
If img.HasFile AndAlso Not img.PostedFile Is Nothing Then
'To create a PostedFile
Dim File As HttpPostedFile = PicUpload.PostedFile
'Create byte Array with file len
imgByte = New Byte(File.ContentLength - 1) {}
'force the control to load data in array
File.InputStream.Read(imgByte, 0, File.ContentLength)
End If
If IsPostBack Then
'declare the file path to store uploads
Dim path As String = Server.MapPath("~/Uploads/")
Dim fileOK As Boolean = False
'check the file to make sure it is of the required type
Dim fileExtension As String
fileExtension = System.IO.Path. _
GetExtension(FileUpload1.FileName).ToLower()
'declare the allowed extentions
Dim allowedExtensions As String() = _
{".mov", ".wmv", ".avi", ".mp4", ".m4v", ".flv"}
'loop to check the extention type
For i As Integer = 0 To allowedExtensions.Length - 1
If fileExtension = allowedExtensions(i) Then
fileOK = True
End If
Next
'******************* Write Video Immage And Details into the Database *******************************
Dim conn As String = ConfigurationManager.ConnectionStrings("projectConnectionString").ConnectionString
Try
FileUpload1.FileName.DefaultIfEmpty()
Dim FilePath = path & FileUpload1.FileName
connection = New SqlConnection(conn)
connection.Open()
Dim sql As String = "INSERT INTO EmpData (DateOfUpload, DescOfWork,WorkDone,ComOfEmp,Picture,EmpUsername,Video)VALUES (@en1m,@en2m,@en3m,@en4m,@eimg,@en5m,@VideoUrl)SELECT @@IDENTITY"
Dim cmd As SqlCommand = New SqlCommand(sql, connection)
If Not fileok1 Or imgByte Is Nothing Then
sql = "INSERT INTO EmpData (DateOfUpload, DescOfWork,WorkDone,ComOfEmp,EmpUsername,Video)VALUES (@en1m,@en2m,@en3m,@en4m,@en5m,@VideoUrl)SELECT @@IDENTITY"
cmd = New SqlCommand(sql, connection)
MsgBox("wrong format or no image to upload")
Else
cmd.Parameters.AddWithValue("@eimg", imgByte)
End If
cmd.Parameters.AddWithValue("@en1m", Calendar1.SelectedDate.Date)
cmd.Parameters.AddWithValue("@en2m", TypeOfWork.Text.Trim())
cmd.Parameters.AddWithValue("@en3m", WorkOfTheDay.Text.Trim())
cmd.Parameters.AddWithValue("@en4m", ComOfEmp.Text.Trim())
cmd.Parameters.AddWithValue("@en5m", Request.QueryString("id"))
If fileOK Then
cmd.Parameters.AddWithValue("@VideoUrl", FilePath)
Else
MsgBox("the video was not saved ")
cmd.Parameters.AddWithValue("@VideoUrl", DBNull.Value)
End If
Dim id As Integer = Convert.ToInt32(cmd.ExecuteScalar())
FileUpload1.PostedFile.SaveAs(path & _
FileUpload1.FileName)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Response.Redirect("Employee.aspx?id=" + TextBox1.Text, False)
End If
End Sub
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click, TextBox2.Load
TextBox2.Text = Request.QueryString("id")
End Sub
Protected Sub ShowEmpData(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged, Calendar2.Load
End Sub
Protected Sub delete(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)
End Sub
End Class
I'm always receiving this error when I click on save plz please can sm1 someone help me here ?
this is the error :
Server Error in '/WebSite2' Application.
HTTP Error 400 - Bad Request.
Version Information: ASP.NET Development Server 10.0.0.0