Hello everyone,
I'm new here and hope that someone can help. I'm also new to .NET & VB so please bear with my need for hand holding.
I've got files being uploaded from my web server to a file server. To avoid filename duplication, I'm adding a date/time tag to the filename just before the file extension (if there's one). All this is working fine (upload). The date/time tag has the following format "_YYYYMMDDHHMMSS". Thus, a filename would look like "Hello_20060920192530.txt". Note that there is not always a filename extension, depending on what has been uploaded.
But when I want to list the files, I want to strip the date/time tag before the filename is displayed and make the filename a hyperlink to the file's UNC name when it's clicked. Thus, the above example would be displayed as "Hello.txt" with the hyperlink pointing to the full UNC name.
Here's what I have so far. Any help would be greatly appreciated. Thanks for all the help.
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
'Put together path and file name
Dim strPath as string
Dim strDirName as string
strPath = "\\myserver\PROJECTS\"
strDirName = Dir(strPath, vbDirectory) ' Retrieve the first entry.
if strDirName <> "" ' The folder exists
Dim dirInfo as New DirectoryInfo(strPath)
Dim xFiles
xFiles = dirInfo.GetFiles("*.*")
Dim fileDate(xFiles.GetUpperBound(0)) as Date
'Get the Last Written Time of each file
For i as Integer = 0 to xFiles.GetUpperBound(0) step 1
fileDate(i) = xFiles(i).LastWriteTime
Next i
'Use the Last Written Time as the key on which to sort the files
'Method syntax is PAIR of one-dimensional arrays where 1st array contains keys used to sort 2nd array
Array.Sort(fileDate, xFiles)
'Reverse the sort order if required
'Array.Reverse(xFiles)
articleList.DataSource = xFiles
articleList.DataBind()
else
response.Write("<b>No files have been attached to this request.</b>")
end if
End Sub
</script>
<asp:DataGrid runat="server" id="articleList" Font-Name="Arial"
AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee"
HeaderStyle-BackColor="#cccccc" HeaderStyle-ForeColor="White"
HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True">
<Columns>
<asp:HyperLinkColumn DataTextField="Name" HeaderText="Name" Target="_self" DataNavigateUrlField="FullName" ItemStyle-HorizontalAlign="left" DataNavigateUrlFormatString="{0:d}" ItemStyle-Width="400px" />
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Date" ItemStyle-HorizontalAlign="left" DataFormatString="{0:d}" ItemStyle-Width="100px" />
<asp:BoundColumn DataField="Length" HeaderText="Size" ItemStyle-HorizontalAlign="left" DataFormatString="{0:#,### bytes}" ItemStyle-Width="150px" />
</Columns>
</asp:DataGrid>
<html>
<body>
</body>
</html>