title: HttpWebRequest command to get directory listing
body: <p>In the following post I followed the examples to create my httprequest and list files from webServer directory: 
  <a href="https://stackoverflow.com/questions/124492/c-httpwebrequest-command-to-get-directory-listing">C# HttpWebRequest command to get directory listing</a></p>
  
  <p>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:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;186.215.156.154 - /download/Zatix/Zatix - Satisfação Geral/&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;
          186.215.156.154 - /download/Zatix/Zatix - Satisfação Geral/&lt;/h1&gt;
      &lt;hr&gt;
      &lt;pre&gt;
      &lt;a href="/download/Zatix/"&gt;[Para a pasta superior]&lt;/a&gt;
      &lt;br&gt;
      &lt;br&gt;
      sexta-feira, 19 de novembro de 2010    11:17        52355 &lt;a href="/download/Zatix/Zatix%20-%20Satisfa%C3%A7%C3%A3o%20Geral/Zatix%20-%20Satisfa%C3%A7%C3%A3o%20Geral_3_00.zip"&gt;Zatix - Satisfação Geral_3_00.zip&lt;/a&gt;&lt;br&gt;sexta-feira, 19 de novembro de 2010    11:17        52355 &lt;a href="/download/Zatix/Zatix%20-%20Satisfa%C3%A7%C3%A3o%20Geral/Zatix%20-%20Satisfa%C3%A7%C3%A3o%20Geral_4_00.zip"&gt;Zatix - Satisfação Geral_4_00.zip&lt;/a&gt;
      &lt;br&gt;
  &lt;/pre&gt;
      &lt;hr&gt;
  &lt;/body&gt;
  &lt;/html
  </code></pre>
  
  <p>I think I have to change something in the return of GetDirectoryListingRegexForUrl method.</p>
  
  <p>My code is something like this:</p>
  
  <pre><code>private string GetDirectoryListingRegexForUrl(string url)
  {
      if (url.Equals(Url));
      {
          return "&lt;A HREF=\".*\"&gt;(?&lt;name&gt;.*)&lt;/A&gt;";                   
      }
      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 &gt; 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);
      }            
  }
  </code></pre>
  
  <p>I hope you can help me! Thanks.</p>