In the following post I followed the examples to create my httprequest and list files from webServer directory: C# HttpWebRequest command to get directory listing
I'm trying to use the example there to list files from my web server. I can list the files from the example server quoted on the link, but my server just shows the last added file. My code is exactly like the example there. I noticed that my html code is a little different. Someone have an idea:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>186.215.156.154 - /download/Zatix/Zatix - Satisfação Geral/</title>
</head>
<body>
<h1>
186.215.156.154 - /download/Zatix/Zatix - Satisfação Geral/</h1>
<hr>
<pre>
<a href="/download/Zatix/">[Para a pasta superior]</a>
<br>
<br>
sexta-feira, 19 de novembro de 2010 11:17 52355 <a href="/download/Zatix/Zatix%20-%20Satisfa%C3%A7%C3%A3o%20Geral/Zatix%20-%20Satisfa%C3%A7%C3%A3o%20Geral_3_00.zip">Zatix - Satisfação Geral_3_00.zip</a><br>sexta-feira, 19 de novembro de 2010 11:17 52355 <a href="/download/Zatix/Zatix%20-%20Satisfa%C3%A7%C3%A3o%20Geral/Zatix%20-%20Satisfa%C3%A7%C3%A3o%20Geral_4_00.zip">Zatix - Satisfação Geral_4_00.zip</a>
<br>
</pre>
<hr>
</body>
</html
I think I have to change something in the return of GetDirectoryListingRegexForUrl method.
My code is something like this:
private string GetDirectoryListingRegexForUrl(string url)
{
if (url.Equals(Url));
{
return "<A HREF=\".*\">(?<name>.*)</A>";
}
throw new NotSupportedException();
}
public void ListStudies()
{
Url = BaseUrl + this.clientName + "/" + this.activeStudy + "/";
Console.WriteLine(Url);
CookieContainer cookies;
HttpWebResponse response;
HttpWebRequest req = (HttpWebRequest)System.Net.WebRequest.Create(Url);
req.Credentials = _NetworkCredential;
req.CookieContainer = new CookieContainer();
req.AllowAutoRedirect = true;
cookies = req.CookieContainer;
try
{
response = (HttpWebResponse)req.GetResponse();
if (response.StatusCode != HttpStatusCode.OK)
Console.WriteLine("URL NÃO RESPONDEU");
else
Console.WriteLine("URL OK");
using (response)
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string html = reader.ReadToEnd();
Regex regex = new Regex(GetDirectoryListingRegexForUrl(Url));
MatchCollection matches = regex.Matches(html);
if (matches.Count > 0)
{
foreach (Match match in matches)
{
if (match.Success)
{
Console.WriteLine(match.Groups["name"]);
}
}
}
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
I hope you can help me! Thanks.