getting number of files

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)
 
P

Patrice

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.
 
B

bj daniels

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)
 
M

mortb

Something like this might work?

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

cheers,
mortb
 
K

Kevin Spencer

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.
 
B

bj daniels

just tried that - it didn't work because the media is stored on a different
server.
thanks for the idea though.

bj daniels
 
P

Patrice

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
 
B

bj daniels

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
 
B

bj daniels

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

bj
 
K

Kevin Spencer

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.
 
B

bj daniels

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.
 

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

Top