Reputation: 2045
I have a gridview that looks something like this:
<TemplateColumn>
<ItemTemplate>
<a href='<%#Eval("FilePathUrl")%>'>FileName</a>
</ItemTemplate>
<ItemTemplate>
<a href='<%#Eval(sysUtilities.GetFilePath("FilePathLocation") & "FilePathUrl")%>'>FileDateTime</a>
</ItemTemplate>
</TemplateColumn>
The file is located at sysUtilities.GetFilePath("FilePathLocation")
sysUtilities is a class in the App_Code folder
GetFilePath is method
I need help with the syntax
How can I display the file's date time created in the gridView (by that I mean what is the correct syntax for):
<a href='<%#Eval(sysUtilities.GetFilePath("FilePathLocation") & "FilePathUrl")%>'>FileDateTime</a>
Upvotes: 2
Views: 2414
Reputation: 55210
Try this.
Markup
<asp:TemplateColumn HeaderText="Created At">
<ItemTemplate>
<asp:Label ID="FileCreationTime" runat="server"
Text='<%# GetFileCreatedTime(Eval(FilePathLocation), Eval(FilePathUrl) ) %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
Code-behind
Protected Function GetFileCreatedTime(location As Object, url As Object) As String
Dim path As String = sysUtilities.GetFilePath(location.ToString()) & url.ToString()
Dim fi1 As FileInfo = New FileInfo(path)
If fi1.Exists Then
Return fi1.CreationTime.ToString()
Else
Return ""
End If
End Function
On an unrelated side-note, you are using asp:DataGrid
and not .asp:GridView
Upvotes: 1
Reputation: 6802
try this:
<ItemTemplate>
<a href='<%#Eval(sysUtilities.GetFilePath("FilePathLocation") & "FilePathUrl")%>'>
<%#System.IO.File.GetCreationTime(sysUtilities.GetFilePath("FilePathLocation") & Eval("FilePathUrl").ToString())%>
</a>
</ItemTemplate>
Upvotes: 3
Reputation: 243
Take a look here: http://www.csharp-examples.net/file-creation-modification-time/ for several examples on how to retrieve the file time. You can either use the FileInfo class or the File class, both of them exposing the same properties for retrieving the creation date time
Upvotes: 1