图片不能显示问题,(很奇怪)帮帮我吧
1。//上传部分
private void BtnOK_ServerClick(object sender, System.EventArgs e)
{
//获取上传文件路径
string filepath=Server.MapPath("file/" + Path.GetFileName(File1.PostedFile.FileName));
//验证用户输入是否合法
if((title.Text=="")||(content.Text==""))
{
Label1.Text="标题、内容不能为空";
return;
}
else if(title.Text.Length>=50)
{
Label1.Text="你的标题太长了!";
return;
}
else if(File1.PostedFile.ContentLength>153600)
{
Span1.Text="上传的文件不能超过70kb";
return;
}
else if(File.Exists(filepath))
{
Span1.Text="上传文件重名,请改名后再上传";
return;
}
else
{
if(File1.PostedFile!=null)
try
{
//保存上传文件
File1.PostedFile.SaveAs(filepath);
}
catch(Exception exc)
{
Span1.Text="保存文件时出错<b>"+filepath+"</b><br>"+exc.ToString();
}
string strconn=ConfigurationSettings.AppSettings["dsn"];
SqlConnection myconnection=new SqlConnection(strconn);
SqlCommand mycommand=new SqlCommand("insert into news(title,content,zhaizi,fabutime,click,img)values('"+title.Text.ToString()+"','"+content.Text.ToString()+"','"+zhaizi.Text.ToString()+"','"+DateTime.Now.ToString()+"',0,'"+Path.GetFileName(File1.PostedFile.FileName)+"')",myconnection);
mycommand.Connection.Open();
mycommand.ExecuteNonQuery();
mycommand.Connection.Close();
Response.Redirect("morenews.aspx");
}
}
2.显示图片<%if (dr["img"].ToString()!=""){%>
<IMG src='file/<%=dr["img"] %>'>
<%}%>
为什么就不能保存到我的文件file里呀?