getting number of files

  • Thread starter Thread starter bj daniels
  • Start date Start date
B

bj daniels

I am trying to get the number of .jpg files in a given folder (to pick a
random one). The folder is referenced by a url - how can I do this. I have
tried the code below - but get an error that URLs are not accepted.
Dim files As String() = System.IO.Directory.GetFiles(dir, "*.jpg")

result = files.Length



thanks



bj daniels

(e-mail address removed)
 
AFAIK System.IO.Directory is for file system based files.

If these files are on your local site, you'll have to convert the URL to a
physical location using Server.MapPath.
 
They are not local to the site, they are on a separate site that is
dedicated to serving up media. I just don't want to start mapping drives or
creating shares. Is there an equivalent function that can work with a url
based path?

bj daniels
(e-mail address removed)
 
Something like this might work?

Dim files As String() = System.IO.Directory.GetFiles(Server.MapPath(dir),
"*.jpg")

cheers,
mortb
 
creating shares. Is there an equivalent function that can work with a url
based path?

No. Is the separate site on the same machine? If so, you can use the file
path to the folder in question. Otherwise, you're pretty much at the mercy
of whatever the "separate site" makes publicly available.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
just tried that - it didn't work because the media is stored on a different
server.
thanks for the idea though.

bj daniels
 
Either a request (? WebDav) or perhaps expose this info from the other site.
If the other site handles media files, how are they exposed ?

Patrice
 
I just reference the url of the media I want (generally jpg) - it allows us
not to have to move media all over our site easily. this other site,
doesn't have any code.

bj
 
if there an easy way to make that info available? Is that what a web
service would do?

bj
 
One possibility: If the files reside in a folder that doesn't contain a
default page, and if the web server allows directory browsing, you could use
a WebRequest to the folder, which should get back a page with a listing of
all the files in the directory. You could then parse that page and get the
file listing out of it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
thanks


Kevin Spencer said:
One possibility: If the files reside in a folder that doesn't contain a
default page, and if the web server allows directory browsing, you could use
a WebRequest to the folder, which should get back a page with a listing of
all the files in the directory. You could then parse that page and get the
file listing out of it.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top