C# OpenFileDialog上传附件(C# openfiledialog upload attachments)

System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.Filter = “DataBank(*.xml)|*.xml|全部文件(*.*)|*.*”;openFileDialog.Multiselect = true;//是否允许多选,false表示单选

System.Windows.Forms.DialogResult dr = openFileDialog.ShowDialog();if (dr == System.Windows.Forms.DialogResult.OK){undefined

//openFileDialog.FileNames 获取对话框中所有选定文件的文件名(String 类型数组),为绝对路径,类似”E:\\code\\123.xml” foreach(var FileName in openFileDialog.FileNames) {undefined System.IO.FileInfo file = new System.IO.FileInfo(FileName);//如果是单选,FileName=openFileDialog.FileName if (file.Extension == “.xml”) {undefined GetFileData(FileName);//根据文件名路径获取文件数据逻辑 } else {undefined MessageBox.Show(“请选择xml文件,目前仅支持对xml数据读取!”); return; } }}————————————————版权声明:本文为CSDN博主「hx_windy」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/hx_windy/article/details/92773717

————————

System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.Filter = “DataBank(*.xml)|*.xml|全部文件(*.*)|*.*”;openFileDialog.Multiselect = true;//是否允许多选,false表示单选

System.Windows.Forms.DialogResult dr = openFileDialog.ShowDialog();if (dr == System.Windows.Forms.DialogResult.OK){undefined

//openFileDialog. Filenames gets the file names (string type array) of all selected files in the dialog box, which are absolute paths, Similar to “E: \ \ code \ \ 123. XML” foreach (VaR filename in openfiledialog. Filenames) {undefined system.io.fileinfo file = new system. Io. FileInfo (filename); / / if it is a single choice, filename = openfiledialog. Filename if (file. Extension = = “. XML”) {undefined getfiledata (filename) ;// Obtain the file data logic according to the file name and path} else {undefined MessageBox. Show (“please select an XML file. Currently, only XML data reading is supported!”); return; } }}———————————————— Copyright notice: This is the original article of CSDN blogger “hx_windy”, which follows the CC 4.0 by-sa copyright agreement. Please attach the original source link and this notice for reprint. Original link: https://blog.csdn.net/hx_windy/article/details/92773717