By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,383 Members | 1,993 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,383 IT Pros & Developers. It's quick & easy.

Reading a list of files from a directory

P: n/a
Is it possible to read a list of files from a specified directory using
VB.net

We have company intranet and I have created a page that displays photos from
different events.
I have coded a page that display images from a particular directory and
named the files Pic1.jpg, Pic2.jpg etc. My code then cycles through the
images and displays them in the browser. I store the current image number in
a session variable and apply it to the image control when the page is
loaded. The user then clicks a button to go to the next image.

To be honest all this works absolutely fine. If I add pictures I have to
rename the new files and change a constant in my code so that you can't
browse past the last image. This really isn't much of a probelm, but I was
wondering if there was a way of reading the contents of a directory using
vb.net and store them say in the cache object as an array. That way I can
get the number of files dynamically rather that having to recode.

Just curious and hoping to expand on the little bit of knowledge I have.

Many thanks in advance
Nick.

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
1. Get the actual directory to search it, rather than the URL.
2. Set up a DirectoryInfo object and point to that directory
3. Loop through the directory Info files collection
4. Grab file name and append the relative URL to it

You should be able to handle the image display, as you are already doing that.

NOTE: Another option is to have a piece of code that runs through the
directory and creates an XML file with the image links. You can have this
automatically set up, as a FileWatcher service, for example, or have it run
when you kick it off. The benefit here is you do not have to rescan images
every hit on the page. If you do the non-watcher version, you can also
publish images before you are ready to show them and rescan when you are
ready.
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Nick" wrote:
Is it possible to read a list of files from a specified directory using
VB.net

We have company intranet and I have created a page that displays photos from
different events.
I have coded a page that display images from a particular directory and
named the files Pic1.jpg, Pic2.jpg etc. My code then cycles through the
images and displays them in the browser. I store the current image number in
a session variable and apply it to the image control when the page is
loaded. The user then clicks a button to go to the next image.

To be honest all this works absolutely fine. If I add pictures I have to
rename the new files and change a constant in my code so that you can't
browse past the last image. This really isn't much of a probelm, but I was
wondering if there was a way of reading the contents of a directory using
vb.net and store them say in the cache object as an array. That way I can
get the number of files dynamically rather that having to recode.

Just curious and hoping to expand on the little bit of knowledge I have.

Many thanks in advance
Nick.


Nov 19 '05 #2

P: n/a
Awesome..
Thanks Gregory.

Never used the DirectoryInfo object but will look it up in the help files.

I'm very new to asp.net so you've lost me a little with the FileWatcher
service (although understand the XML concept), I'll scan the help etc for
info.

Many thanks.
Nick
"Cowboy (Gregory A. Beamer) - MVP" <No************@comcast.netNoSpamM> wrote
in message news:B2**********************************@microsof t.com...
1. Get the actual directory to search it, rather than the URL.
2. Set up a DirectoryInfo object and point to that directory
3. Loop through the directory Info files collection
4. Grab file name and append the relative URL to it

You should be able to handle the image display, as you are already doing
that.

NOTE: Another option is to have a piece of code that runs through the
directory and creates an XML file with the image links. You can have this
automatically set up, as a FileWatcher service, for example, or have it
run
when you kick it off. The benefit here is you do not have to rescan images
every hit on the page. If you do the non-watcher version, you can also
publish images before you are ready to show them and rescan when you are
ready.
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Nick" wrote:
Is it possible to read a list of files from a specified directory using
VB.net

We have company intranet and I have created a page that displays photos
from
different events.
I have coded a page that display images from a particular directory and
named the files Pic1.jpg, Pic2.jpg etc. My code then cycles through the
images and displays them in the browser. I store the current image number
in
a session variable and apply it to the image control when the page is
loaded. The user then clicks a button to go to the next image.

To be honest all this works absolutely fine. If I add pictures I have to
rename the new files and change a constant in my code so that you can't
browse past the last image. This really isn't much of a probelm, but I
was
wondering if there was a way of reading the contents of a directory using
vb.net and store them say in the cache object as an array. That way I can
get the number of files dynamically rather that having to recode.

Just curious and hoping to expand on the little bit of knowledge I have.

Many thanks in advance
Nick.


Nov 19 '05 #3

P: n/a
Just tried the DirectoryInfo and the FileInfo objects and they work
perfectly..

Now all I need to do is work out how to set up the FileWatcher Service...
Think I may be some time. :o)

Nick

"Cowboy (Gregory A. Beamer) - MVP" <No************@comcast.netNoSpamM> wrote
in message news:B2**********************************@microsof t.com...
1. Get the actual directory to search it, rather than the URL.
2. Set up a DirectoryInfo object and point to that directory
3. Loop through the directory Info files collection
4. Grab file name and append the relative URL to it

You should be able to handle the image display, as you are already doing
that.

NOTE: Another option is to have a piece of code that runs through the
directory and creates an XML file with the image links. You can have this
automatically set up, as a FileWatcher service, for example, or have it
run
when you kick it off. The benefit here is you do not have to rescan images
every hit on the page. If you do the non-watcher version, you can also
publish images before you are ready to show them and rescan when you are
ready.
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Nick" wrote:
Is it possible to read a list of files from a specified directory using
VB.net

We have company intranet and I have created a page that displays photos
from
different events.
I have coded a page that display images from a particular directory and
named the files Pic1.jpg, Pic2.jpg etc. My code then cycles through the
images and displays them in the browser. I store the current image number
in
a session variable and apply it to the image control when the page is
loaded. The user then clicks a button to go to the next image.

To be honest all this works absolutely fine. If I add pictures I have to
rename the new files and change a constant in my code so that you can't
browse past the last image. This really isn't much of a probelm, but I
was
wondering if there was a way of reading the contents of a directory using
vb.net and store them say in the cache object as an array. That way I can
get the number of files dynamically rather that having to recode.

Just curious and hoping to expand on the little bit of knowledge I have.

Many thanks in advance
Nick.


Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.