Referentiel.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Web;
  6. using System.Xml;
  7. namespace CD67.FicheCollege.MVC.Internal
  8. {
  9. public class Referentiel
  10. {
  11. /// <summary>
  12. /// Fonction qui interroge l'index SolR du référentiel commune pour retourner les codes postaux par communes
  13. /// </summary>
  14. /// <param name="Insee">Code Insee de la commune souhaitée</param>
  15. /// <returns>Liste des codes postaux possibles</returns>
  16. public static List<string> GetCodesPostaux(string Insee)
  17. {
  18. //cas de sortie immédiat
  19. if (Insee == null) return new List<string>();
  20. var m_strFilePath = String.Format(Properties.Settings.Default.GetCodesPostaux_URL, Insee);
  21. string xmlStr;
  22. using (var wc = new WebClient())
  23. {
  24. xmlStr = wc.DownloadString(m_strFilePath);
  25. }
  26. var xmlDoc = new XmlDocument();
  27. xmlDoc.LoadXml(xmlStr);
  28. //Recherche des données
  29. List<string> result = new List<string>();
  30. foreach (XmlNode item in xmlDoc.GetElementsByTagName("str"))
  31. {
  32. result.Add(item.InnerText);
  33. }
  34. return result;
  35. }
  36. }
  37. }