Here is a script for displaying name of files (for download) in data grid table. Is it possible that to show the latest created file in top row?. Please help.
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack then
Dim dirInfo As New DirectoryInfo("D:\SeverUpload\Safety")
articleList.DataSource = dirInfo.GetFiles("*.*")
articleList.DataBind()
End If
End Sub
Sub articleList_ItemDataBound(sender as Object, e as DataGridItemEventArgs)
' First, make sure we're NOT dealing with a Header or Footer row
If e.Item.ItemType <> ListItemType.Header AND _
e.Item.ItemType <> ListItemType.Footer then
'Now, reference the Button control that the Delete ButtonColumn
'has been rendered to
Dim deleteButton as Button = e.Item.Cells(0).Controls(0)
'We can now add the onclick event handler
deleteButton.Attributes("onclick") = "javascript:return " & _
"confirm('Are you sure you want to delete the file " & _
DataBinder.Eval(e.Item.DataItem, "Name") & "?')"
End If
End Sub
Sub articleList_DeleteFile(sender as Object, e as DataGridCommandEventArgs)
'First, get the filename to delete
Dim fileName as String = articleList.DataKeys(e.Item.ItemIndex)
'lblMessage.Text = "You opted to delete the file " & _
'fileName & ".<br />" & _
'"This file could be deleted by calling: " & _
'"<code>File.Delete(FileName)</code><p>"
'You would want to rebind the Directory's files to the DataGrid after
'deleting the file...
End Sub
</script>