<INPUT id="upimage" type="file" runat="server">
图片上传到指定目录]
 同时将文本信息提交到数据库中

解决方案 »

  1.   

    文本信息你从哪里输入呢??
    是不是应该多加一个textbox控件呢?
    再判断upimage对象的内容类型合法且textbox不为空时,先传upimage到指定目录,指保存textbox的值到数据库.
      

  2.   

    如果是需要文本信息和图片放在一起,就使用FreeTextBox控件,不过也要注意图片的路径.
      

  3.   

    3、上传图片
    CODE:  [Copy to clipboard]
    --------------------------------------------------------------------------------System.Drawing.Image image,newimage;                                     //定义image类的对象
                    protected string imagePath;                                              //图片路径
                    protected string imageType;                                              //图片类型
                    protected string imageName;
                    protected System.Web.UI.WebControls.RadioButtonList choice;                                              //图片名称
                    System.Drawing.Image.GetThumbnailImageAbort callb =null;                 //提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行,如果此方法确定GetThumbnailImage方法应提前停止执行,则返回true,否则返回false
    CODE:  [Copy to clipboard]
    --------------------------------------------------------------------------------private void btn_upload_Click(object sender, System.EventArgs e)
                    {
                            string mPath,img_source,img_small;
                            string pid = Request.QueryString["pid"];
                            string typeid = Request.QueryString["typeid"];
                            string typef = Request.QueryString["typef"];                        if(""!= upImage.PostedFile.FileName)
                            {
                                    imagePath = upImage.PostedFile.FileName;
                                    //取得图片类型
                                    imageType = imagePath.Substring(imagePath.LastIndexOf(".")+1);
                                    //取得图片名称
                                    imageName = DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+imagePath.Substring(imagePath.LastIndexOf("\\")+1);
                                    if("jpg"!= imageType && "gif"!= imageType )
                                    {
                                            Response.Write("<script language='javascript'>alert('对不起!请您选择jpg或者gif格式的图片!');</script>");
                                            return;
                                    }
                                    else
                                    {
                                            
                                            mPath = Server.MapPath("../../picture");                                                                        //建立虚拟路径
                                            upImage.PostedFile.SaveAs(mPath+"\\"+imageName);                                                        //保存到虚拟路径
                                            img_source = "picture/" + imageName;                          //显示原图
                                            image = System.Drawing.Image.FromFile(mPath+"\\"+imageName);                                                //为上传的图片建立引用
                                            newimage = image.GetThumbnailImage(184,148,callb,new System.IntPtr());                                        //生成缩略图
                                            newimage.Save(Server.MapPath("../../picture")+"\\small"+imageName);                                                //把缩略图保存到指定的虚拟路径
                                            image.Dispose();                                                                                        //释放image对象占用的资源
                                            newimage.Dispose();                                                                                        //释放newimage对象的资源
                                            img_small = "picture/" + "small" + imageName;                 //显示缩略图                                        
                                            string imgid = pub.AddImage(txt_name.Text,img_source,img_small,txt_author.Text,Int32.Parse(pid),Int32.Parse(typeid));
                                            if (imgid != "")
                                            {
                                                    string UserChoice = choice.SelectedValue;
                                                    switch(UserChoice)
                                                    {
                                                            case "1":
                                                                    Response.Redirect ("index.aspx?typeid="+typeid+"&typef="+typef+"&pid="+pid+"");
                                                                    break;
                                                            case "2":
                                                            {
                                                                    txt_name.Text = "";
                                                                    txt_author.Text = "";
                                                            }
                                                                    break;
                                                    }
                                            }
                                            else
                                            {
                                                    txtMessage.Text ="不好意思,上传图片失败!";                                        }
                                    }
                            }        
                    } 给分