private void ButtonOpenFile_Click(object sender, EventArgs e) { simbolDialog = true; OpenFileDialog filename = new OpenFileDialog(); //定义一个文件打开控件 XmlReader xmlReader = null; try { //加载xml文档 xmlReader = new XmlTextReader(Application.StartupPath + @"\xml\dbconnect.xml");//参数:存储的绝对路径 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlReader); XmlNode root = xmlDoc.DocumentElement; //获取根节点 XmlNode lastFilePath = root.SelectSingleNode("//lastFilePath"); if (lastFilePath != null) { filename.InitialDirectory = lastFilePath.InnerText; //打开的默认目录为exe所在目录 } else { filename.InitialDirectory = Application.StartupPath; //打开的默认目录为exe所在目录 } } catch (Exception ex) { //MessageBox.Show(ex.Message); } finally { xmlReader.Close(); } filename.Multiselect = true; // 允许多选 filename.Filter = "npz文件(*.npz)|*.npz|NPZ文件(*.NPZ)|*.NPZ|mseed文件(*.mseed)|*.mseed|MSEED文件(*.MSEED)|*.MSEED|sac文件(*.sac)|*.sac|SAC文件(*.SAC)|*.SAC|txt文件(*.txt)|*.txt|TXT文件(*.TXT)|*.TXT|csv文件(*.csv)|*.csv|CSV文件(*.CSV)|*.CSV"; // 设置控件打开的文件类型 filename.FilterIndex = 1; //设置控件打开文件类型的显示顺序 filename.RestoreDirectory = false; //是否记忆之前打开的目录 if (filename.ShowDialog() == DialogResult.OK) { AllFilePath = null; //发布完之后清空路径 AllFileName.Clear(); //发布完之后清空内容 int FileNum = filename.FileNames.Length; for (int i = 0; i < FileNum; i++) { string Path = filename.FileNames[i].ToString(); //获得用户选择的文件的绝对路径 string ParentPath = Path.Substring(0, Path.LastIndexOf(@"\")); //获取用户选择的文件的绝对路径的上一级路径,用于存放txt文件 string CurrentFileName = Path.Substring(Path.LastIndexOf("\\") + 1); //获取用户选择的不带路径的文件 string TxtName = "input" + DateTime.Now.ToString("HHmmss") + ".txt"; //设置生成的txt文件的名字 //output("用户选择的文件目录为:" + ParentPath); //打印出用户选择的文件目录 //output(""); Output("The file that the user has selected:" + CurrentFileName); //打印出用户选择的文件名 AllFileName.Add(CurrentFileName); AllFilePath = ParentPath; AllUploadFiles.Add(Path); //当前循环的绝对路径 AllRecievePaths.Add(InputFilePath_global + @"\" + CurrentFileName); //当前循环的输入文件夹存储路径 AllFileType = FormMain.getType(CurrentFileName); //获取选择文件的格式 Console.WriteLine(AllFileType); } try { string url = Application.StartupPath + @"\xml\dbconnect.xml"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(url); XmlNode lastFilePath = xmlDoc.SelectSingleNode("//lastFilePath"); if (AllFilePath != null) { lastFilePath.InnerText = AllFilePath; } xmlDoc.Save(url); } catch (Exception ex) { MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private int downloadNum = 0; //for online public FormChart() { InitializeComponent(); if (FormLogin.language == true) { this.Text = "图表"; ButtonLast.Text = "上一张"; ButtonNext.Text = "下一张"; } if (FormLogin.if_online) { var result = FormMain.sshClient.RunCommand("ls " + FormMain.outPutPath_online + "/figures"); if (result.Result == "") { result = FormMain.sshClient.RunCommand("ls " + FormMain.outPutPath_online + "/figures_top"); } string[] file_list = result.Result.Split('\n'); if (FormMain.picture_begin == "pl") { Directory.CreateDirectory(FormMain.outPutPath + @"\figures"); foreach (var file_name in file_list) { if (file_name != "") { FormMain.download(FormMain.outPutPath_online + "/figures/" + file_name, FormMain.outPutPath + "/figures/" + file_name); } } } else { Directory.CreateDirectory(FormMain.outPutPath + @"\figures_top"); foreach (var file_name in file_list) { if (file_name != "") { FormMain.download(FormMain.outPutPath_online + "/figures_top/" + file_name, FormMain.outPutPath + "/figures_top/" + file_name); } } } } string[] files; if (FormMain.picture_begin == "pl") { files = Directory.GetFiles(FormMain.outPutPath + @"\figures"); } else { files = Directory.GetFiles(FormMain.outPutPath + @"\figures_top"); } chartNames = files; if (files.Length == 0) { MessageBox.Show("No best picture found!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Bitmap MyBitMap = new Bitmap(chartNames[picNum]); pictureBox.Image = MyBitMap; labelFileName.Text = chartNames[picNum]; } }