分类：电脑/网络-互联网
问题：asp.2.0/C#关于FileUpload控件上传图片 
回答：try        {            string name = FileUpload1.FileName;            string size = FileUpload1.PostedFile.ContentLength.ToString();            string type = name.Substring(name.LastIndexOf(".") + 1).ToLower();            if (type == "jpg" || type == "png" || type == "bmp" || type == "gif" || type == "jpeg")            {                try                {                    ImgUploads iu = new ImgUploads(DropDownList1.SelectedItem.Text);                    String id=iu.GetMaxId();//获取最大ID号用来命名图片                    String ReName = id + "." + type;//图片重命名                    String Ipath = Server.MapPath("~/hy/upimg") + "\\" + ReName;//文件实际路径                    FileUpload1.SaveAs(Ipath);//上传到图片目录                    String Tpath = Server.MapPath("~/hy/thumbar") + "\\" + ReName;//缩略图路径                    PictureSlightly.MakeImage(Ipath,Tpath,100,130,"hw");//生成缩略图//上传到数据库                    iu.UpImg(Convert.ToInt32(id),DropDownList1.SelectedItem.Text,ReName.ToString());                    Label1.Text = "上传成功,图片大小:" + size + "B";                     umbar.Src = "~/hy/thumbar/" + ReName;                }                catch(Exception ex)                {                    Page.RegisterStartupScript("error", "<script>alert('图片上传失败,请重试!"+ex.Message.ToString()+"');</script>");                }                            }            else            {                Page.RegisterStartupScript("error", "<script>alert('图片格式不对!');</script>");            }        }        catch        {            Page.RegisterStartupScript("error", "<script>alert('图片上传失败,请重试!');</script>");        }    }