Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :
CSS
Server Error in '/WebSite2' Application.
HTTP Error 400 - Bad Request.
Version Information: ASP.NET Development Server 10.0.0.0
Posted
Updated 26-Apr-12 11:45am
v2
Comments
kroz18 26-Apr-12 16:36pm    
plz if an1 can help me i'll apreciate that :(
wizardzz 26-Apr-12 16:38pm    
Stop replying to your own post. We don't care how urgent it is. We answer for free, on our time. You posted this 11 minutes ago, what do you expect people to do? You provided a ton of code and it would take that long to even read it. Also, why are you talking in text speak?
kroz18 26-Apr-12 16:47pm    
i'm sorry if i disturbed an1 i didn't mean that
Shahin Khorshidnia 26-Apr-12 17:47pm    
Hello?! Please do not use "plz", "sm1". You have enough time to type "Please", "Some one". It's a technical site not SMS!
kroz18 26-Apr-12 17:57pm    
ok done i will not use them again sorry but i'm used to write like that

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