Home  >  Article  >  Backend Development  >  Sample code for C# Winform program to upload pictures to a specified directory

Sample code for C# Winform program to upload pictures to a specified directory

黄舟
黄舟Original
2017-03-10 13:43:442606browse

单机版程序上传,只能上传到本地目录,并不适合网络应用,看来只能单机版能这么用。网络程序要使用上传图片还得继续改造。

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;
                }            
}



The above is the detailed content of Sample code for C# Winform program to upload pictures to a specified directory. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn