-1

I am new to C#. I have to download files from HTTP web link.

I have created a string like this:

string baseURL =  "http://ladsweb.nascom.nasa.gov/opendap/allData/51/MOD08_D3/2013/278";
WebClient client = new WebClient();
string content = client.DownloadString(baseURL);
string[] filePaths = Directory.GetFiles(content, "*.hdf");

I have to download files from folder 278 which has extension of hdf. but Exception shown like this "Illegal characters in path" I have to create string and for julian day (here 278) I have to modify string and pass it to webclient. what is the best way to get the files from http link .

user28542
  • 145
  • 8
  • 1
    `content` is not a directory, it's a string. `Directory.GetFiles` is used with actual directories, where the string parameter is the path to the directory. Have you tried stepping through your code to see what `content` is? – Tim Jan 13 '16 at 04:30
  • 1
    Your title makes no sense. But you can't give a *web page* to `Directory.GetFiles()`. It doesn't parse HTML. – Sami Kuhmonen Jan 13 '16 at 04:30

1 Answers1

0

If you're looking to download the files from the URL:

https://ladsweb.nascom.nasa.gov/opendap/hyrax/allData/51/MOD08_D3/2013/278/

It looks like they provide an XML representation of the files in this directory/catalog:

https://ladsweb.nascom.nasa.gov/opendap/hyrax/allData/51/MOD08_D3/2013/278/catalog.xml

Your best approach to download the files in this catalog would be to...

Step One: Parse the XML to extract the URLs of the images within the catalog. Here is a useful Stackoverflow post to achieve this first step: Parsing XML file using C#?.

Step Two: Using the the list of image URLs from step one, go through and download the actual images. Here are some useful posts outlining how to download images using .NET's WebClient.

Download image from the site in .NET/C#

Using a WebClient to save an image with the appropriate extension

I hope this provides a general overview on how to achieve your desired functionality.

~Josh

Community
  • 1
  • 1
Josh Greenberg
  • 323
  • 1
  • 7