R
rn5a
Consider the following code:
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath("/Folder1"))
dgFD.DataSource = dInfo.GetFiles("*.*")
dgFD.DataBind()
End Sub
</script>
<form runat="server">
<aspataGrid ID="dgFD" runat="server"/>
</form>
The above code works fine & populates the DataGrid with all the files
residing in the directory named "Folder1". But it doesn't get the sub-
directories residing in "Folder1". In order to populate the DataGrid
with both the files & sub-directories residing in "Folder1", I
replaced the line
dgFD.DataSource = dInfo.GetFiles("*.*")
with
dgFD.DataSource = dInfo.GetFileSystemInfos("*.*")
But now when I run the above code, ASP.NET generates the following
error:
Object does not match target type.
pointing to the line
dgFD.DataBind()
What is wrong with the above code? How do I populate the DataGrid with
both the files as well as the sub-directories residing in the
directory named "Folder1"?
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath("/Folder1"))
dgFD.DataSource = dInfo.GetFiles("*.*")
dgFD.DataBind()
End Sub
</script>
<form runat="server">
<aspataGrid ID="dgFD" runat="server"/>
</form>
The above code works fine & populates the DataGrid with all the files
residing in the directory named "Folder1". But it doesn't get the sub-
directories residing in "Folder1". In order to populate the DataGrid
with both the files & sub-directories residing in "Folder1", I
replaced the line
dgFD.DataSource = dInfo.GetFiles("*.*")
with
dgFD.DataSource = dInfo.GetFileSystemInfos("*.*")
But now when I run the above code, ASP.NET generates the following
error:
Object does not match target type.
pointing to the line
dgFD.DataBind()
What is wrong with the above code? How do I populate the DataGrid with
both the files as well as the sub-directories residing in the
directory named "Folder1"?