Skip to content

Listing files from a web site?

Joshua Chambers

Asked Jun 17, 2008, 9:50 AM EDT1 answer
Share
LinkedInX
Hello, I am having a very hard time figuring out exactly which class I need to use to do what I need to do here.  What I need to do is to get a list of all the files in a certain directory on a remote website (using it's http:// URI), and download each of those files, even delete those files after I've fetched them.

I've been looking at the WebRequest and WebResponse objects, but I only seem to be able to get the index page from the location, not a list of the files in that directory, and the DirectoryInfo class doesn't seem to take a remote URI, only a local reference.

If anyone has an idea, I would really appreciate it!

Thanks,
Joshua

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mahesh Chand
    0

    You need to use Directory class and first get all subdirectories recursively and then in each subdirectory and root directory, get files using Directory.GetFiles method. After you get a list of files, you go through each file using the File class and call its delete method and use Directory.Delete to delete a directory. However, you would need admin permissions on the folders to delete the directory and files. 

    You should start with this article:

    http://msdn.microsoft.com/en-us/library/07wt70x2.aspx

    0