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

黄舟
Release: 2017-03-10 13:43:44
Original
2605 people have browsed it

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

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;
                }            
}
Copy after login



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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!