再次请求,文件(arr.jpg.doc之类的)上传后,把路径存入数据库的代码
再次请求,文件(arr.jpg.doc之类的)fileupload上传后,文件保存在服务器的指定目录,如test,把绝对路径http://localhost/test/test.doc存入数据库
万分感谢
[解决办法]
手边刚好有个,这个是把路径格式化成时间了然后路径存放数据库里 protected void Button1_Click(object sender, EventArgs e) { string rootUrl = Server.MapPath("~/img/") + DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+ ".jpg"; string imgUrl = "~/img/" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString() + ".jpg"; cimg.PostedFile.SaveAs(rootUrl); ShopModel_commodity commodity = new ShopModel_commodity(); commodity.Commodity_name = cname.Text; commodity.Commodity_price = cprice.Text; commodity.Commodity_text = ctext.Text; commodity.Commodity_picurl = imgUrl; //图片路径 commodity.Commodity_type = DropDownList1.SelectedValue; commodity.Commodity_adduser = cadder.Text; commodity.Commodity_addtime = DateTime.Now; if (ShopDal.AddNewCommodity(commodity)) { Response.Write("<script>alert(\"添加商品成功\");window.location='admin.aspx'</script>"); } else { Response.Write("<script>alert(\"添加商品失败\")</script>"); } }