上传图片

li453174970 2009-04-26 03:09:30
在ASP中选中一张图片然后将其保存在E:\program\pic文件夹下,将图片显示在网业上,保存按纽后将图片的相对路径记录在SQL server 数据库中
...全文
41 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dengyun_1223 2009-04-26
  • 打赏
  • 举报
回复
不是很好。高手不要扔我
dengyun_1223 2009-04-26
  • 打赏
  • 举报
回复
给个例子。我以前做的。你参考一下
protected void btnsubmit_Click(object sender, EventArgs e)
{
if (upImages.HasFile)
{
if (CheckImageType(upImages.FileName))
{
string ImagePath = "~/uploadImage/" + upImages.FileName;
upImages.SaveAs(MapPath(ImagePath));
SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings["Conn"].ToString());
SqlCommand cmd = new SqlCommand("insert into PPhoto(photoImage) values(@photoImage)", cn);
cmd.Parameters.AddWithValue("@photoImage", "~/uploadImage/" + upImages.FileName);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('上传成功');</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('上传失败');</script>");
}
}
}

private bool CheckImageType(string ImageName)
{
string ext = Path.GetExtension(ImageName);
switch (ext.ToLower())
{
case ".gif": return true;
case ".png": return true;
case ".jpg": return true;
case ".jpeg": return true;
default: return false;
}
}
dengyun_1223 2009-04-26
  • 打赏
  • 举报
回复
以前我做过的。
boy1234648 2009-04-26
  • 打赏
  • 举报
回复
学习!!!
wuyq11 2009-04-26
  • 打赏
  • 举报
回复
wndsc 2009-04-26
  • 打赏
  • 举报
回复
string Path = Server.MapPath("~/image");
FileUpload1.PostedFile.SaveAs(Path + "\\" + Product.picture);

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧