private void btnUpload_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "请挑选上传的图片"; ofd.Filter = "图片格式|*.jpg"; //设置是不是许可多选 ofd.Multiselect = false; if (ofd.ShowDialog()== System.Windows.Forms.DialogResult.OK) { //取得文件的完全途径(包含名字后后缀) string filePath = ofd.FileName; tbImgFile.Text = filePath; int position = filePath.LastIndexOf("\\"); string fileName = filePath.Substring(position+1); File.Copy(ofd.FileName, Application.StartupPath + "\\Upload\\" + fileName); pbImage.ImageLocation = Application.StartupPath + "\\Upload\\" + fileName; } }
以上就是C# Winform顺序上传图片到指定目次的示例代码的细致内容,更多请关注ki4网别的相干文章!