转:上传图片到服务器文件佳
以下是本在网站找的源码,希望对大家有点帮助: Code protected void btnAdd_Click( object sender, EventArgs e) // 上传事件 { bool fileOK = false ; string path = Server.MapPath( " ~/images/productPic/ " ); // 上传到服务器上的指定路径 if (FileUpload1.HasFile) // 如果有上传文件,则判断文件类型 { String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); String[] allowedExtensions = { " .gif " , " .png " , " .bmp " , " .jpg " }; for ( int i = 0 ; i < allowedExtensions.Length; i ++ ) { if (fileExtension == allowedExtensions[i]) { fileOK = true ; } } } if (fileOK) { try { string timeStr = Convert.ToString(DateTime.Now.Year) +