R
rn5a
A ListBox lists all the files & directories existing in a directory on
the server. If an item in the ListBox happens to be a directory, then
the name of the directory is appended with the text [DIR]. Similarly,
if an item in the ListBox happens to be a file, then the name of the
file is appended with the text [FILE]. Assuming that the ListBox lists
2 directories & 3 files, this is how the ListBox would look like:
MyDir1 [DIR]
MyDir2 [DIR]
File1.aspx [FILE]
File2.aspx [FILE]
File3.aspx [FILE]
Since I want the ListBox to add additional information of each
directory & file, I am adding the items to the ListBox using the Add
method & not using the DataSource property to bind the directories &
files to the ListBox:
Sub Page_Load(.....)
Dim fsi As FileSystemInfo
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath("Folder1"))
For Each fsi In dInfo.GetFileSystemInfos
If ((fsi.Attributes And FileAttributes.Directory) = 16) Then
lstFD.Items.Add(fsi.Name & " [DIR]")
Else
lstFD.Items.Add(fsi.Name & " [FILE]")
End If
Next
End Sub
When I have s look at the source of the ListBox, I find that the value
assigned to each item in the ListBox is exactly the same as the text of
the item like this:
<select id="lstFD">
<option value="MyDir1 [DIR]">MyDir1 [DIR]</option>
<option value="MyDir2 [DIR]">MyDir2 [DIR]</option>
<option value="File1.aspx [FILE]">File1.aspx [FILE]</option>
<option value="File2.aspx [FILE]">File2.aspx [FILE]</option>
<option value="File3.aspx [FILE]">File3.aspx [FILE]</option>
</select>
As is evident above, the value of each item & its corresponding text is
exactly the same.
I want to remove the text [DIR] & [FILE] appended to each directory &
file respectively ONLY from the value of each item so that the value of
each item gets set to just the directory or the file name i.e. the
source of the ListBox should be
<select id="lstFD">
<option value="MyDir1">MyDir1 [DIR]</option>
<option value="MyDir2">MyDir2 [DIR]</option>
<option value="File1.aspx">File1.aspx [FILE]</option>
<option value="File2.aspx">File2.aspx [FILE]</option>
<option value="File3.aspx">File3.aspx [FILE]</option>
</select>
How do I accomplish this?
I tried adding the following code immediately after For....Next loop
starts (i.e. just before the If condition)
lstFD.DataValueField = fsi.Name
but that doesn't make any difference. The value of each item still
remains exactly the same as its corresponding text.
the server. If an item in the ListBox happens to be a directory, then
the name of the directory is appended with the text [DIR]. Similarly,
if an item in the ListBox happens to be a file, then the name of the
file is appended with the text [FILE]. Assuming that the ListBox lists
2 directories & 3 files, this is how the ListBox would look like:
MyDir1 [DIR]
MyDir2 [DIR]
File1.aspx [FILE]
File2.aspx [FILE]
File3.aspx [FILE]
Since I want the ListBox to add additional information of each
directory & file, I am adding the items to the ListBox using the Add
method & not using the DataSource property to bind the directories &
files to the ListBox:
Sub Page_Load(.....)
Dim fsi As FileSystemInfo
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath("Folder1"))
For Each fsi In dInfo.GetFileSystemInfos
If ((fsi.Attributes And FileAttributes.Directory) = 16) Then
lstFD.Items.Add(fsi.Name & " [DIR]")
Else
lstFD.Items.Add(fsi.Name & " [FILE]")
End If
Next
End Sub
When I have s look at the source of the ListBox, I find that the value
assigned to each item in the ListBox is exactly the same as the text of
the item like this:
<select id="lstFD">
<option value="MyDir1 [DIR]">MyDir1 [DIR]</option>
<option value="MyDir2 [DIR]">MyDir2 [DIR]</option>
<option value="File1.aspx [FILE]">File1.aspx [FILE]</option>
<option value="File2.aspx [FILE]">File2.aspx [FILE]</option>
<option value="File3.aspx [FILE]">File3.aspx [FILE]</option>
</select>
As is evident above, the value of each item & its corresponding text is
exactly the same.
I want to remove the text [DIR] & [FILE] appended to each directory &
file respectively ONLY from the value of each item so that the value of
each item gets set to just the directory or the file name i.e. the
source of the ListBox should be
<select id="lstFD">
<option value="MyDir1">MyDir1 [DIR]</option>
<option value="MyDir2">MyDir2 [DIR]</option>
<option value="File1.aspx">File1.aspx [FILE]</option>
<option value="File2.aspx">File2.aspx [FILE]</option>
<option value="File3.aspx">File3.aspx [FILE]</option>
</select>
How do I accomplish this?
I tried adding the following code immediately after For....Next loop
starts (i.e. just before the If condition)
lstFD.DataValueField = fsi.Name
but that doesn't make any difference. The value of each item still
remains exactly the same as its corresponding text.