Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C# VB
how can i get a list of folders from a website? Namely I wrote a program that take a URL And give a list of folders from the website.
I try
Directory.GetDirectories(myURL)
but it not work.
Posted 11-Jul-13 9:06am
Comments
ThePhantomUpvoter at 11-Jul-13 14:13pm
   
You would need to ask the web site owner, nicely, to have a list of folders on his website. Or provide a way for you to query that information.
pasztorpisti at 11-Jul-13 15:14pm
   
I don't know about any REQUEST METHOD in the HTTP PROTOCOL that could be used to list directories. More about the HTTP protocol here: http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) You can download a file (GET) or upload a file (PUT) but there is not directory listing operation. A web server may generate you a directory listing "html page" that is not standard parsable data but even this directory listing is usually disabled by default. Once I needed a directory listing feature and I implemented it as a custom HTTP request (LISTDIR) with a python cgi script.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Considering very few websties ever give you browse access to their file system, you're going to have a hard time finding a website that this tool will work with.
 
The Directory class only works with local file systems. It will not work over HTTP, meaning you can't use it for getting the list of directories on a website.
 
You would have to use the HttpWebRequest class with web URLs and parse the result you get back, if any.
  Permalink  
Comments
karimi5555 at 11-Jul-13 14:30pm
   
may further explain please
Dave Kreskowiak at 11-Jul-13 15:14pm
   
Read: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx
 
You would have to request the URL you're trying to get the directory list for, usually ending in a forward slash, like this:
http://www.yahoo.com/
 
IF folder browsing is turned on, you'll get back a page listing the directories in the root of the web site. You parse this text (it's just a string!) and pull out the directory names and links to subdirectories.
 
But, NOBODY in their right mind will turn folder browsing on for their site. Doing so just gives people who want to break into your site more information on how to do it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 265
2 Praneet Nadkar 237
3 Marcin Kozub 225
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100