R
rn5a
In my application, I want to populate all the directories & files
existing in a directory on the server in a DataGrid. To ensure that
all the directories get listed first followed by all the files, I am
appending all the directories with 0 & all the files with 1.
Moreover, each directory & file listed in the DataGrid will have a
corresponding CheckBox. To differentiate between directories & files,
I am adding the string "*D" (without the quotes) to all the
directories & the string "*F" (again, without the quotes) to all the
files. I want to assign the corresponding CheckBoxes these IDs. For
e.g. if one of the directories is named "JOE", then the ID of the
CheckBox should be "chkJOE*D". Similarly, if there is a file named
"MyFile.txt", then its corresponding CheckBox should have the ID
"chkMyFile.txt*F".
There are 2 problems I am facing. First of all, I cannot display all
the directories & files in the DataGrid. Secondly, how do I ensure
that the ID of the CheckBoxes are assigned the string which I
mentioned above? This is the code:
<script runat="server">
Dim dInfo As DirectoryInfo
Sub Page_Load(.......)
dInfo = New DirectoryInfo(Server.MapPath("Directory1"))
Call ListFilesDirs(dInfo)
End Sub
Sub ListFilesDirs(ByVal dirInfo As DirectoryInfo)
Dim i As Integer
Dim iFind As Integer
Dim strURL As String
Dim strSize As String
Dim fInfo As FileInfo
Dim aList As ArrayList
Dim strListItem As String
Dim fsi As FileSystemInfo
aList = New ArrayList
For Each fsi In dirInfo.GetFileSystemInfos
If ((fsi.Attributes And FileAttributes.Directory) = 16)
Then
aList.Add("0" & fsi.Name & "<DIR>")
Else
fInfo = CType(fsi, FileInfo)
strSize = CStr(fInfo.Length)
If (strSize = 0) Then
strSize = "0.00"
End If
aList.Add("1" & fsi.Name & " - " & strSize & " MB - "
& fsi.CreationTime)
End If
Next
aList.Sort()
For i = 0 To aList.Count - 1
If (InStr(aList(i), "<DIR>") > 0) Then
strListItem = Left(aList(i), Len(aList(i)) - 6)
strListItem = Mid(strListItem, 2,
Len(strListItem)) & "*D"
Else
strListItem = Left(aList(i), InStr(aList(i), " -
") - 1)
strListItem = Mid(strListItem, 2,
Len(strListItem)) & "*F"
End If
'Response.Write(Mid(aList(i), 2, Len(aList(i))) &
"<br>")
dgDomain.DataSource = Mid(aList(i), 2, Len(aList(i)))
dgDomain.DataBind()
Next
End Sub
</script>
Note the commented Response.Write line just above the
dgDomain.DataSource line. When I uncomment this Response.Write line,
then all the directories & files get listed one after the other
correctly but they don't get populated in the DataGrid.
Note that the CheckBoxes should be displayed in the very first column
in the DataGrid. The Header of this first column should be a CheckBox
too so that checking/unchecking this Header CheckBox will check/
uncheck all the other CheckBoxes respectively.
Can someone please help me out with this?
existing in a directory on the server in a DataGrid. To ensure that
all the directories get listed first followed by all the files, I am
appending all the directories with 0 & all the files with 1.
Moreover, each directory & file listed in the DataGrid will have a
corresponding CheckBox. To differentiate between directories & files,
I am adding the string "*D" (without the quotes) to all the
directories & the string "*F" (again, without the quotes) to all the
files. I want to assign the corresponding CheckBoxes these IDs. For
e.g. if one of the directories is named "JOE", then the ID of the
CheckBox should be "chkJOE*D". Similarly, if there is a file named
"MyFile.txt", then its corresponding CheckBox should have the ID
"chkMyFile.txt*F".
There are 2 problems I am facing. First of all, I cannot display all
the directories & files in the DataGrid. Secondly, how do I ensure
that the ID of the CheckBoxes are assigned the string which I
mentioned above? This is the code:
<script runat="server">
Dim dInfo As DirectoryInfo
Sub Page_Load(.......)
dInfo = New DirectoryInfo(Server.MapPath("Directory1"))
Call ListFilesDirs(dInfo)
End Sub
Sub ListFilesDirs(ByVal dirInfo As DirectoryInfo)
Dim i As Integer
Dim iFind As Integer
Dim strURL As String
Dim strSize As String
Dim fInfo As FileInfo
Dim aList As ArrayList
Dim strListItem As String
Dim fsi As FileSystemInfo
aList = New ArrayList
For Each fsi In dirInfo.GetFileSystemInfos
If ((fsi.Attributes And FileAttributes.Directory) = 16)
Then
aList.Add("0" & fsi.Name & "<DIR>")
Else
fInfo = CType(fsi, FileInfo)
strSize = CStr(fInfo.Length)
If (strSize = 0) Then
strSize = "0.00"
End If
aList.Add("1" & fsi.Name & " - " & strSize & " MB - "
& fsi.CreationTime)
End If
Next
aList.Sort()
For i = 0 To aList.Count - 1
If (InStr(aList(i), "<DIR>") > 0) Then
strListItem = Left(aList(i), Len(aList(i)) - 6)
strListItem = Mid(strListItem, 2,
Len(strListItem)) & "*D"
Else
strListItem = Left(aList(i), InStr(aList(i), " -
") - 1)
strListItem = Mid(strListItem, 2,
Len(strListItem)) & "*F"
End If
'Response.Write(Mid(aList(i), 2, Len(aList(i))) &
"<br>")
dgDomain.DataSource = Mid(aList(i), 2, Len(aList(i)))
dgDomain.DataBind()
Next
End Sub
</script>
Note the commented Response.Write line just above the
dgDomain.DataSource line. When I uncomment this Response.Write line,
then all the directories & files get listed one after the other
correctly but they don't get populated in the DataGrid.
Note that the CheckBoxes should be displayed in the very first column
in the DataGrid. The Header of this first column should be a CheckBox
too so that checking/unchecking this Header CheckBox will check/
uncheck all the other CheckBoxes respectively.
Can someone please help me out with this?