uploadfile上传图片

时间:2013-12-20 11:28:27
【文件属性】:

文件名称:uploadfile上传图片

文件大小:40KB

文件格式:DOC

更新时间:2013-12-20 11:28:27

使用uploadfile上传

.cs 界面代码 using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; public partial class _Default : System.Web.UI.Page { string name="b";//根据需要给上传的图片命名 int minsize=1;//上传文件的最低大小,单位kb int maxsize=1000;//上传文件的最大大小,单位kb protected void Page_Load(object sender, EventArgs e) { } protected void upload_Click(object sender, EventArgs e) { string fileName, fileExtension, FullName; if (UpImage.PostedFile != null) { if (UpImage.PostedFile.ContentLength != 0 && UpImage.PostedFile.ContentLength <= (1024 * maxsize) && UpImage.PostedFile.ContentLength >= (1024 * minsize)) { fileName = System.IO.Path.GetFileName(UpImage.PostedFile.FileName); fileExtension = System.IO.Path.GetExtension(fileName); if (IsExtension(fileExtension)) { try { FullName = name; CreateDir("upLoadImg"); FullName = DateTime.Now.ToString("yyyyMM") + "/" + FullName; UpImage.PostedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(@"UpFiles/upLoadImg/") + FullName); } catch (Exception ex) { Response.Write(""); } } else { Response.Write(""); } } else { Response.Write(""); } } }


网友评论

  • 用到了,不错不错不错