dois je creer une class comme dans l'exemple avec par exemple
[XmlIgnore()] public bool MonBool { get { ... } set { ... } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionusing System; using System.Xml; using System.Xml.Serialization; namespace WindowsFormsApplication1 { public class sauvegardefilm { private string _NFO = "Unknow"; private string _emplacement = "Unknow"; private string _fichier = "Unknow"; /// ------------------------------------------------------------------------------------------------ /// <summary> /// Constructeur sans paramètre obligatoire pour que l'object soit Serializable ! /// </summary> /// ------------------------------------------------------------------------------------------------ public sauvegardefilm() { } #region Pas Intéressant (Autres Ctor) public sauvegardefilm(string NFO, string emplacement, string fichier) { this._NFO = NFO; this._emplacement = emplacement; this._fichier = fichier; } #endregion [XmlElement("NFO")] /// <summary> /// Cette property est publique et sera donc serializée. /// </summary> /// ------------------------------------------------------------------------------------------------ public string presNFO { get { return this._NFO; } set { this._NFO = value; } } [XmlElement("Repertoire")] public string Rep { get { return this._emplacement; } set { this._emplacement = value; } } [XmlElement("NOMFICHIER")] public string Fich { get { return this._fichier; } set { this._fichier = value; } } } }
// On créer une collection de personnes. List<sauvegardefilm> listefilm = new List<sauvegardefilm>(3); try { foreach (string f in Directory.GetFiles(sDir, pattern)) { bool skipFile = false; foreach (string item in filtre) { if (f.ToUpper().IndexOf(item.ToUpper()) != -1) { skipFile = true; } } if (!skipFile) { if (File.Exists(f.Substring(0, f.LastIndexOf(".")) + ".nfo")) { dataGridView1.Rows.Add(true, f.Substring(0, f.LastIndexOf("\") + 1), f.Substring(f.LastIndexOf("\") + 1)); listefilm.Add(new sauvegardefilm("oui", f.Substring(0, f.LastIndexOf("\") + 1),f.Substring(f.LastIndexOf("\") + 1))); } else dataGridView1.Rows.Add(false, f.Substring(0, f.LastIndexOf("\") + 1), f.Substring(f.LastIndexOf("\") + 1)); } } foreach (string d in Directory.GetDirectories(sDir)) { DirSearch(d, pattern); } } catch (System.Exception excpt) { MessageBox.Show(excpt.Message); } Configurations cfg = new Configurations(); cfg.person = listefilm; // On y set notre collection de personne. }
dataGridView1.Rows.Add(true, f.Substring(0, f.LastIndexOf("\") + 1), f.Substring(f.LastIndexOf("\") + 1)); listefilm.Add(new sauvegardefilm("oui", f.Substring(0, f.LastIndexOf("\") + 1),f.Substring(f.LastIndexOf("\") + 1)));
cfg.person = listefilm
Configurations cfg = new Configurations(); cfg.person = listefilm; // On y set notre collection de personne.
private void DirSearch(string sDir, string pattern) { try { // On créer une collection de personnes. List<sauvegardefilm> listefilm = new List<sauvegardefilm>(3); foreach (string f in Directory.GetFiles(sDir, pattern)) { bool skipFile = false; foreach (string item in filtre) { if (f.ToUpper().IndexOf(item.ToUpper()) != -1) { skipFile = true; } } if (!skipFile) { if (File.Exists(f.Substring(0, f.LastIndexOf(".")) + ".nfo")) { // dataGridView1.Rows.Add(true, f.Substring(0, f.LastIndexOf("\") + 1), f.Substring(f.LastIndexOf("\") + 1)); listefilm.Add(new sauvegardefilm("oui", f.Substring(0, f.LastIndexOf("\") + 1), f.Substring(f.LastIndexOf("\") + 1))); } else { listefilm.Add(new sauvegardefilm("non", f.Substring(0, f.LastIndexOf("\") + 1), f.Substring(f.LastIndexOf("\") + 1))); } // dataGridView1.Rows.Add(false, f.Substring(0, f.LastIndexOf("\") + 1), f.Substring(f.LastIndexOf("\") + 1)); } } foreach (string d in Directory.GetDirectories(sDir)) { DirSearch(d, pattern); } } catch (System.Exception excpt) { MessageBox.Show(excpt.Message); } dataGridView1.DataSource = sauvegardefilmBindingSource; }
mais en fait c est le configurations qui n'est pas reconnu j'ai le droit a un beau message d'erreur
Erreur 1 Le type ou le nom d'espace de noms 'Configurations' est introuvable
(une directive using ou une référence d'assembly est-elle manquante ?)Il y a deux solutions, soit tu changes le namespace de l'un ou l'autre soit dans la classe de scan tout en haut tu écrits
Using NameSpaceDeLAutre;
'System.Collections.Generic.List<WindowsFormsApplication1.sauvegardefilm>' en 'System.Windows.Forms.BindingSource'