ASP.NET+C# FILEUPLOAD控件,如何上传图片到服务器并保存图片路径到数据库?
展开全部
我做了个例子给你
前台:
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server"
Text="Button" onclick="Button1_Click" />
<asp:Image ID="Image1" runat="server" />
</div>
后台:
protected void Button1_Click(object sender, EventArgs e)
{
FileUpload1.SaveAs(Server.MapPath("img/"+FileUpload1.FileName));//上传图片
Image1.ImageUrl = "~/img/" + FileUpload1.FileName;//图片路径(将这个数据保存到数据库就可以了。img为项目里一个文件夹的名称)
}
前台:
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server"
Text="Button" onclick="Button1_Click" />
<asp:Image ID="Image1" runat="server" />
</div>
后台:
protected void Button1_Click(object sender, EventArgs e)
{
FileUpload1.SaveAs(Server.MapPath("img/"+FileUpload1.FileName));//上传图片
Image1.ImageUrl = "~/img/" + FileUpload1.FileName;//图片路径(将这个数据保存到数据库就可以了。img为项目里一个文件夹的名称)
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询