14 enero 2014

Listar los archivos de una carpeta en C#


private void ListarArchivos_Click(object sender, EventArgs e) { try { string startupPath = Application.StartupPath; using (FolderBrowserDialog dialog = new FolderBrowserDialog()) { dialog.Description = "Open a folder which contains the xml output"; dialog.ShowNewFolderButton = false; dialog.RootFolder = Environment.SpecialFolder.MyComputer; if(dialog.ShowDialog() == DialogResult.OK) { string folder = dialog.SelectedPath; foreach (string fileName in Directory.GetFiles(folder, "*.xml", SearchOption.TopDirectoryOnly)) { SQLGenerator.GenerateSQLTransactions(Path.GetFullPath(fileName)); } } } } catch (Exception exc) { MessageBox.Show("Import failed because " + exc.Message + " , please try again later."); } }
Posted in