Asp.net fileUpLoad怎么上传文件 (图片)

来源:百度知道 编辑:UC知道 时间:2024/07/07 23:15:30
我想用fileuploade做一个上传,我做的是后台,我能添加到数据库,可是只是路径,当现实到前台出现的只是路径值,而不是图片。没传上去。请大家帮帮忙吧!谢啦!
上传之后是传到哪了啊,是不是应该传到我的程序里的image里的啊。可是我这里就是把绝对路径保存的数据库里了。还是现实不出来啊。我用的是三层

protected void Button1_Click(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString.ToString();

string fullname = FileUpload1.PostedFile.FileName;
FileInfo fi = new FileInfo(fullname);
string name = fi.Name;
string type = fi.Extension;
if (".gif" == type || ".jpg" == type || ".Gif" == type || ".JPG" == type)
{
//定义保存图片的路径
string savepath = Server.MapPath("~/image");
//保存上传的图片
FileUpload1.PostedFile.SaveAs(savepath + "\\" + name);
string picurl=savepath+"\\"+name;
Response.Write("<script>alert('图片上传成功')</script>");
try
{
SqlConnection conn = new SqlConnect