WebRequest - download files from directory without knowing name of file

C

CodeMotion

I have access to an internet directory and files will be placed in
this directory periodically. I am writing a service to poll that
directory and download the files for processing. I have figured out
how to download the files if I have the name of the file. However, I
will not know the names of these files that I need to download. So,
Is there a way to download a file from a directory in which you do not
know the name of the file?

I am currently using the HttpWebRequest/HttpWebResponse objects to do
this. Here is some code that accomplishes my task.
*********************************************************************
Dim site As String =
"https://somedomain.com/somedirectory/somefilename.xml"
Dim authuri As String = "https://somedomain.com"
Dim userName As String = "u"
Dim password As String = "p"
Dim domain As String = "www.somedomain.com"
Dim receipt As String = Nothing

'Prepare authentication header
Dim einfoCache As New CredentialCache()
einfoCache.Add(New Uri(authuri), "Basic", New
NetworkCredential(userName, password))
einfoCache.Add(New Uri(authuri), "Digest", New
NetworkCredential(userName, password, domain))

Dim request As WebRequest = HttpWebRequest.Create(site)
With request
.Credentials = einfoCache
.PreAuthenticate = False
.ContentType = "text/xml"
.Method = "GET"
End With

Dim response As WebResponse = request.GetResponse()
Dim reader As StreamReader = New
StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8)
receipt = reader.ReadToEnd()
****Code Omitted From Here Down****
*********************************************************************

The 'site' var is the problem child. I can download the file if I
know the name but I need to be able to find the name...then download
it. Any help will be greatly appreciated.

Thanks
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top