Add Function View latest attachment file details only

Dec 5 2022 5:58 AM

How I can add the function of view the latest attachment file only.

 

CODE: attachment.aspx.vb

Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration

Public Class Attachment
    Inherits System.Web.UI.Page
    Dim SqlConnection As String = ConfigurationManager.ConnectionStrings(RSTCSqlConnection").ConnectionString

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim referenceID As Integer = Request.QueryString("RefID")

        If Not Me.IsPostBack Then
            Using con As SqlConnection = New SqlConnection(SqlConnection)
                Using sda As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM E_Suggestion WHERE RefId = " & referenceID, con)

                    Dim dt As DataTable = New DataTable()
                    sda.Fill(dt)
                    gvImages.DataSource = dt
                    gvImages.DataBind()

                End Using
            End Using
        End If
    End Sub

End Class

 

CODE: default.aspx.vb

Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Imports System.IO

Public Class _Default
    Inherits System.Web.UI.Page
    Dim SqlConnection As String = ConfigurationManager.ConnectionStrings("RSTCSqlConnection").ConnectionString
    Dim checkflag As String
    Dim Attachment As String
    Dim Img As String
    Dim StringImg As String
    Dim link As String
    Dim VideoDBCount As String
    Dim Vidname1, Vidname2, Vidname3, Vidname4, Vidname5 As String

#Region "E-suggestion"
    Private Sub SubmitBtn_Click(sender As Object, e As EventArgs) Handles SubmitBtn.Click
        checkvalidity()
        If checkflag = "1" Then
            PanelsuggestionNotRecieve.Visible = True
            Panelmemo.Visible = False
        Else
            PanelsuggestionRecieve.Visible = True
            Panelmemo.Visible = False
            CreateNewForm()
        End If
    End Sub

    'check validity
    '1 = Empty textbox
    Public Sub checkvalidity()
        If name.Text = "" Then
            name.BorderColor = Drawing.Color.Red
            checkflag = "1"
        End If
        If EmpNo.Text = "" Then
            EmpNo.BorderColor = Drawing.Color.Red
            checkflag = "1"
        End If
        If Email.Text = "" Then
            Email.BorderColor = Drawing.Color.Red
            checkflag = "1"
        End If
        If Form.Text = "" Then
            Form.BorderColor = Drawing.Color.Red
            checkflag = "1"
        End If
    End Sub

    Public Sub CreateNewForm()
        Using con As New SqlConnection(SqlConnection)
            Using cmd As New SqlCommand
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "spCreateForm"

                cmd.Parameters.Add("@EmpId", SqlDbType.VarChar).Value = EmpNo.Text
                cmd.Parameters.Add("@EmpFullName", SqlDbType.VarChar).Value = name.Text
                cmd.Parameters.Add("@Dept", SqlDbType.VarChar).Value = ddDept.SelectedValue
                cmd.Parameters.Add("@Division", SqlDbType.VarChar).Value = ddDivision.SelectedValue
                cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = Email.Text
                cmd.Parameters.Add("@FormType", SqlDbType.VarChar).Value = ddType.SelectedValue
                cmd.Parameters.Add("@Form", SqlDbType.VarChar).Value = Form.Text
                cmd.Parameters.Add("@Status", SqlDbType.VarChar).Value = "NEW"

                'file saving in directory
                'capture path and file name
                If FileUpload1.HasFile Then
                    If Not Directory.Exists(Server.MapPath("../ES/Images/")) Then
                        Directory.CreateDirectory(Server.MapPath("../ES/Images/"))
                    End If

                    Dim AttName As String = System.IO.Path.GetFileName(FileUpload1.FileName)
                    Dim AttLocation As String = "Images/" & AttName
                    FileUpload1.SaveAs(Server.MapPath("../ES/Images/") + AttName)

                    cmd.Parameters.Add("@Attachment", SqlDbType.VarChar).Value = AttName
                    cmd.Parameters.Add("@Path", SqlDbType.VarChar).Value = AttLocation
                Else

                End If

                cmd.Connection = con
                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()
                con.Dispose()

            End Using
        End Using
    End Sub
#End Region