string extension = Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower();
            string type = FileUpload1.PostedFile.ContentType;
            if (type == "image/gif" || type == "image/pjpeg")
            {
                if (FileUpload1.PostedFile.ContentLength > 2097152)
                {
                    ClientScript.RegisterStartupScript(GetType(), "", ("<script>alert('图片太大。');</script>"));
                }
                else
                {
                    Random r = new Random();
                    string random = r.Next(1000, 9999).ToString();  
                    string name = DateTime.Now.ToString("yyyyMMddHHmmss") + random;
                    string directory = "~/UpLoad/"; 
                    string newPath = directory + name + extension;
                    string physics = Server.MapPath(newPath);
                    this.txtImgName.Text = name+extension;
                    FileUpload1.SaveAs(physics);
                    Image1.ImageUrl = "~/upload/" + name + extension;
                }
            }
            else 
            {
                ClientScript.RegisterStartupScript(GetType(), "", ("<script>alert('请选择jpg和gif的图片。');</script>"));
            }我把图片保存到程序里面了,给了数据库这个图片的名字然后我想查看  怎么弄啊

解决方案 »

  1.   

    从数据库查出来。然后赋值给图片控件即可
    datatable dt=new datatable();
    select image from aa;
    if(dt.rows.count>0){
    Image1.ImageUrl=dt.rows[0]["image"].tostring();}
      

  2.   

    吧图片在服务器中的物理地址保存到数据库中,然后再先生的时候直接用<img>元素,这是其src值为该路径即可
      

  3.   

    Image1.ImageUrl = "~/upload/" + name + extension;
    这个Image1不能显示吗? 不过没看到extension的定义。看看路径有没有弄错。
      

  4.   


    这个是预览 
    我是要做一个后台,在后台上显示的 extension的定义上面有的第一行就是哦
      

  5.   


    ....
    这么简单,我先在数据库中查出来保存的这个txtImgName  再加个文件夹名称?