Home > Backend Development > C#.Net Tutorial > asp.net fileupload implements upload

asp.net fileupload implements upload

高洛峰
Release: 2016-12-29 16:57:03
Original
1635 people have browsed it

protected void Button1_Click(object sender, EventArgs e) 
{ 
string filename = this.DropDownList1.SelectedValue;//最终命名 
if (this.FileUpload1.PostedFile != null) 
{ 
string baseFilename = this.FileUpload1.PostedFile.FileName;//获取上传文件文件名 
int i = baseFilename.LastIndexOf("."); 
string ext = baseFilename.Substring(i);//获取文件的扩展名 
string savePath = Server.MapPath("~/pic/"); 
if (!System.IO.Directory.Exists(savePath)) 
{ 
System.IO.Directory.CreateDirectory(savePath ); 
} 
savePath = savePath + "\\" + filename+ext; 
//Response.Write(ext ); 
if (!ext.Equals(".jpg") && !ext.Equals(".jpeg") && !ext.Equals(".bmp") && !ext.Equals(".gif") && !ext.Equals(".png")) 
{ 
Response.Write("上传文件格式不正确!<a href="\" href="\""upload.aspx\">重新上传</a>"); 
Response.End(); 
} 

FileUpload1.PostedFile.SaveAs( savePath ); 
} 
}
Copy after login

更多asp.net fileupload 实现上传相关文章请关注PHP中文网!


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