Elpato92
Messages postés1Date d'inscriptionmardi 4 mars 2014StatutMembreDernière intervention 4 mars 2014
-
4 mars 2014 à 17:02
Bonjour,
Je développe une petite application de recherche de fichier dans des répertoires se trouvant sur le réseau.
J'avais écris une fonction récursive de recherche qui marchait bien mais qui bloque sur des exceptions d'autorisation "unauthorizedaccessexception".
J'ai déniché un petit programme sur un site internet que j'ai modifié :
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Management; using System.Collections; using System.Runtime;
namespace WindowsFormsApplication2 { public partial class Form1 : Form {
public Form1() { InitializeComponent(); //File extensions: comboBox1.Items.Add(" "); comboBox1.Items.Add("PDF Adobe Acrobat (.pdf)"); comboBox1.Items.Add("PostScript (.ps)"); comboBox1.Items.Add("DWF Autodesk (.dwf)"); comboBox1.Items.Add("KLM Google Earth (.klm)"); comboBox1.Items.Add("KMZ Google Earth (.kmz)"); comboBox1.Items.Add("Microsoft Excel (.xls)"); comboBox1.Items.Add("Microsoft PowerPoint (.ppt)"); comboBox1.Items.Add("Microsoft Word (.doc)"); comboBox1.Items.Add("Rich Text Format (.rtf)"); comboBox1.Items.Add("Shockwave Flash (.swf)"); comboBox1.Items.Add("Texte (.txt)");
//List of directories string[] drives = Environment.GetLogicalDrives(); for (int i = 0; i < drives.Length; i++) { comboBox2.Items.Add(drives[i]); }
case " ": filetype = ""; break; case "PDF Adobe Acrobat (.pdf)": filetype = ".pdf"; break;
case "DWF Autodesk (.dwf)": filetype = ".dwf"; break;
case "KLM Google Earth (.klm)": filetype = ".klm"; break;
case "KMZ Google Earth (.kmz)": filetype = ".kmz"; break; case "Microsoft Excel (.xls)": filetype = ".xls"; break; case "Microsoft PowerPoint (.ppt)": filetype = ".ppt"; break; case "Microsoft Word (.doc)": filetype = ".doc"; break; case "Rich Text Format (.rtf)": filetype = ".rtf"; break; case "Shockwave Flash (.swf)": filetype = ".swf"; break; case "Texte (.txt)": filetype = ".txt"; break; default: filetype = ".doc"; break; }*/
//On peut pour rechercher un fichier sur un disque utiliser le namespace System.Management //exemple pour recherche un fichier sur le lecteur C: nommé test avec l'extension .txt
//on construit la requête WMI string qry = String.Format( "select * from cim_logicalfile where drive={0} and filename={1} and extension={2}", drive, filename, extension);
System.Management.ManagementObjectSearcher query = new System.Management.ManagementObjectSearcher(qry);
//a l'aide de cette requête on recupere une collection System.Management.ManagementObjectCollection queryCollection = query.Get(); //on parcourt cette collection pour extraire le resultat de notre requete foreach(System.Management.ManagementObject mo in queryCollection ) { listBox1.Items.Add(mo["Name"]); } listBox1.Items.Add("Search method 1 finished");
} } }
Le souci est que les variables "drive,filename et extension" ne s'affectent pas à partir des contrôles winforms.
Quand j'écris les valeurs à la main ça marche.
Comment peut on relié ces variable à des comboBox ou textBox ???
ça fait 10 jours que je cherche la solution et je n'y arrive pas merci