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程序上传图片到指定目录的示例代码的详细内容。
