List Directories in ListBox

R

rn5a

I am not very sure whether I should have continued with my earlier
thread or started a new thread whose subject matter was somewhat
similar to the subject matter in this thread. Anyway after much
deliberation, I decided to start a new thread. So here it is. Pardon me
if I should have continued with my earlier thread instead of starting
this new thread.

A ListBox lists all the directories & files existing in a directory on
the server. Assume that one of the directories is named the following:

"IHIS IS MY FOLDER"

The double quotes have been added just to show where the directory name
ends; it's not a part of the text.

But the ListBox displays the name of this directory as

"IHIS IS MY FOLDER"

i.e. the ListBox replaces all the whitespaces between words with a
single whitespace.

How do I make the ListBox retain the whitespaces present in the name of
the directory so that the directory listed in the ListBox displays
EXACTLY the same name as the name of the directory which exists in the
hard drive of the server? In other words, how do I make the ListBox
list the above directory as

"IHIS IS MY FOLDER"

& not as

"IHIS IS MY FOLDER"
 
M

Mark Rae

I am not very sure whether I should have continued with my earlier
thread or started a new thread whose subject matter was somewhat
similar to the subject matter in this thread. Anyway after much
deliberation, I decided to start a new thread. So here it is. Pardon me
if I should have continued with my earlier thread instead of starting
this new thread.

A ListBox lists all the directories & files existing in a directory on
the server. Assume that one of the directories is named the following:

"IHIS IS MY FOLDER"

The double quotes have been added just to show where the directory name
ends; it's not a part of the text.

But the ListBox displays the name of this directory as

"IHIS IS MY FOLDER"

i.e. the ListBox replaces all the whitespaces between words with a
single whitespace.

How do I make the ListBox retain the whitespaces present in the name of
the directory so that the directory listed in the ListBox displays
EXACTLY the same name as the name of the directory which exists in the
hard drive of the server? In other words, how do I make the ListBox
list the above directory as

"IHIS IS MY FOLDER"

& not as

"IHIS IS MY FOLDER"

It's standard browser / HTML behaviour to ignore double spaces.

Try replacing each space with   - I haven't tried this, though, so I
can't guarantee it'll work...
 
R

rn5a

Mark, this is how I am populating the ListBox with directories & files:

Sub Page_Load(.....)
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath("Folder1"))
lstFilesDirs.DataSource = dInfo.GetFileSystemInfos
lstFilesDirs.DataBind()
End Sub

Now how do I use the Replace string function while setting the
DataSource of the ListBox so that whitespaces get replaced with  ?

Moreover, I would like to add more information about each directory &
file listed in the ListBox. For e.g. if an item happens to be a
directory, I would like to add a string, say, <DIR> on the same line
where the directory is listed in the ListBox. If an item happens to be
a file, I would like to add the size of the file along with the date &
time on which the file was created on the same line where the file is
listed in the ListBox. The ListBox should look something like this:

Folder1 <DIR>
Folder2 <DIR>
File1.aspx 22346 31/12/2006 5:34:11 AM
File2.aspx 7634 03/01/2007 8:24:52 PM
File3.aspx 2903 05/01/2007 1:16:33 PM

Any idea how do I append the additional info for each directory & file
on the same row where the directory & the file is listed respectively
in the ListBox?

I would like to request everyone to please view this post using the
fixed font. I guess that will give a better picture of how I want the
ListBox to look like with the additional info for each directory &
file.

I guess I am asking for too many favors. Sorry for the same.
 
M

Mark Rae

Mark, this is how I am populating the ListBox with directories & files:

Sub Page_Load(.....)
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath("Folder1"))
lstFilesDirs.DataSource = dInfo.GetFileSystemInfos
lstFilesDirs.DataBind()
End Sub

Now how do I use the Replace string function while setting the
DataSource of the ListBox so that whitespaces get replaced with &nbsp;?

You can't - you'll need to add the items individually through code. That
will allow you to do any sort of string manipulation you like

http://community.strongcoders.com/forums/thread/1477.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top