OpenFileDialog et copier multiple fichier
-
samedi 28 avril 2012 01:38
Bonjour a tous
Mon probleme est le suivant
J'utilise ceci pour ouvrir le repertoire pour choisir les fichier
d'un repertoire et les copier dans un autreprivate void tbImport_Click(object sender, EventArgs e) { OpenFileDialog ofd=new OpenFileDialog(); ofd.InitialDirectory=Environment.GetFolderPath(Environment.SpecialFolder.Personal); ofd.Filter="Fichiers Snippets (*.DMSnip)|*.DMSnip"; ofd.Multiselect = true; if (ofd.ShowDialog(this)==DialogResult.OK) { string FileName = ofd.FileName; //from string dpath=TV1.SelectedNode.FullPath+"\\"; // Destination if (ofd.FileName!="") { FileName = ofd.SafeFileName; //from //to File.Copy(ofd.FileName, dpath + FileName); //reload the file in Treeview LoadNodes(); } }le probleme est que j'obtient seulement le premier fichier du répertoire et pas les autre
j'en ai 50 a copier je procede comment
Merci
Daniel
Toutes les réponses
-
samedi 28 avril 2012 03:13
Bonjour a tous
Mon probleme est le suivant
J'utilise ceci pour ouvrir le repertoire pour choisir les fichier
d'un repertoire et les copier dans un autreprivate void tbImport_Click(object sender, EventArgs e) { OpenFileDialog ofd=new OpenFileDialog(); ofd.InitialDirectory=Environment.GetFolderPath(Environment.SpecialFolder.Personal); ofd.Filter="Fichiers Snippets (*.DMSnip)|*.DMSnip"; ofd.Multiselect = true; if (ofd.ShowDialog(this)==DialogResult.OK) { string FileName = ofd.FileName; //from string dpath=TV1.SelectedNode.FullPath+"\\"; // Destination if (ofd.FileName!="") { FileName = ofd.SafeFileName; //from //to File.Copy(ofd.FileName, dpath + FileName); //reload the file in Treeview LoadNodes(); } }le probleme est que j'obtient seulement le premier fichier du répertoire et pas les autre
j'en ai 50 a copier je procede comment
Merci
Daniel
Bien en fait je vien de trouver ceci dans mes favories de code sur le web
private void tbImport_Click(object sender, EventArgs e) { OpenFileDialog ofd=new OpenFileDialog(); ofd.InitialDirectory=Environment.GetFolderPath(Environment.SpecialFolder.Personal); ofd.Filter="Fichiers Snippets (*.DMSnip)|*.DMSnip"; ofd.Multiselect=true; if (ofd.ShowDialog(this)==DialogResult.OK) { string FileName=ofd.FileName; //from string dpath=Application.StartupPath+"\\"+TV1.SelectedNode.FullPath+"\\"; // Destination if (ofd.FileName!="") { FileName=ofd.SafeFileName; string directoryName=Directory.GetParent(ofd.FileName).FullName; bool copy=CopyDirectory(directoryName, dpath, true); //reload the file in Treeview LoadNodes(); } } } private static bool CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting) { bool ret=false; try { SourcePath=SourcePath.EndsWith(@"\")?SourcePath:SourcePath+@"\"; DestinationPath=DestinationPath.EndsWith(@"\")?DestinationPath:DestinationPath+@"\"; if (Directory.Exists(SourcePath)) { if (Directory.Exists(DestinationPath)==false) Directory.CreateDirectory(DestinationPath); foreach (string fls in Directory.GetFiles(SourcePath)) { FileInfo flinfo=new FileInfo(fls); flinfo.CopyTo(DestinationPath+flinfo.Name, overwriteexisting); } foreach (string drs in Directory.GetDirectories(SourcePath)) { DirectoryInfo drinfo=new DirectoryInfo(drs); if (CopyDirectory(drs, DestinationPath+drinfo.Name, overwriteexisting)==false) ret=false; } } ret=true; } catch //(Exception ex) { ret=false; } return ret; }
et cela semble fonctionner tres bien mais si y a mieu faite le moi savoir MerciDaniel
- Marqué comme réponse DanielMorais samedi 28 avril 2012 03:13
-
jeudi 3 mai 2012 10:41Propriétaire
Bonjour,
Merci pour avoir partagé avec nous la solution.
Bonne journée,
Cipri
Ciprian DUDUIALA, MSFT  
•Nous vous prions de considérer que dans le cadre de ce forum on n’offre pas de support technique et aucune garantie de la part de Microsoft ne peut être offerte.


