I have the following simple page;
<%@ Import namespace="System.IO" %>
<script runat="server">
int pageSize = 10;
int pageNum = 1;
protected override void OnInit(EventArgs e)
{
var currentPage = Directory.GetFiles(@"C:\mypath", "*.pdf").Skip((pageNum - 1) * pageSize).Take(pageSize).OrderBy(c => c).ToArray();
Listview1.DataSource = currentPage;
Listview1.DataBind();
base.OnInit(e);
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test project</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ListView ID="Listview1" runat="server">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td>Titel</td>
<td>Size</td>
</tr>
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><a href=''><%#Eval("Name") %></a></td>
<td>0 kb</td>
</tr>
</ItemTemplate>
</asp:ListView>
</form>
</body>
</html>
How do i get Filename, size, path etc into my Listview. If i just had a simple for each directly on the GetFiles, i could do something like
FileInfo f = new FileInfo(pdfFile);
long pdfSize = f.Length;
Response.Write(Path.GetFileName(pdfFile) + " - " + pdfSize.ToString() + "<br/>");
But how do i achive this in my ListView?
You are selecting the paths to the files not the files itself. Hence you cannot get the
FileInfo‘s properties what raises your exception “DataBinding: ‘System.String’ does not contain a property with the name ‘Name'”This should work: