图片下载问题!

gawz 2003-11-26 04:41:55
请问如果我有一个image和一个button
点button 时要下载 image 上的图片。 该如何做到!

高手救命啊! 已经郁闷一天了。
...全文
35 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
rock1981 2003-11-27
  • 打赏
  • 举报
回复
up
bhys 2003-11-27
  • 打赏
  • 举报
回复
Dim scdirectory As String
Dim scfilename As String
Dim filepath As String
scdirectory = Server.MapPath("files\5.JPG")
scfilename = "5.jpg"
filepath = scdirectory

Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(scfilename, System.Text.Encoding.UTF8))
Response.WriteFile(filepath)
Response.End()
gawz 2003-11-27
  • 打赏
  • 举报
回复
To gOODiDEA(无语) : 大虾,救命啊!
gawz 2003-11-27
  • 打赏
  • 举报
回复
System.Web.HttpContext.Current.Server.MapPath( image1.ImageUrl );
中 image1.ImageUrl 为 "../Other/Image.aspx?Empid=2&picid=1&module=301"

MapPath 中是否不可以存在 "?" 这个字符 。 否则就非法!!! 怎样解决啊?

To billqi(bill) : 还是不可以!

bpy 2003-11-27
  • 打赏
  • 举报
回复
gz
billqi 2003-11-27
  • 打赏
  • 举报
回复
试试
image1.ImageUrl=@"../Other/Image.aspx?Empid=2&picid=1&module=301"
gawz 2003-11-27
  • 打赏
  • 举报
回复

image1.ImageUrl="../Other/Image.aspx?Empid=2&picid=1&module=301"

路径存在非法字符...
gong1 2003-11-27
  • 打赏
  • 举报
回复
无语很猛。
^_^
同意楼上
gOODiDEA 2003-11-27
  • 打赏
  • 举报
回复
System.IO.FileStream fs = System.IO.File.OpenRead( System.Web.HttpContext.Current.Server.MapPath( image1.ImageUrl ) );
byte[] FileData = new byte[ fs.Length ];
fs.Read( FileData, 0, ( int ) fs.Length );
refPage.Response.Clear();
refPage.Response.AddHeader( "Content-Type", MyContentType );
string FileName = System.Web.HttpUtility.UrlEncode( System.Text.Encoding.UTF8.GetBytes( _FileName ) );
refPage.Response.AddHeader("Content-Disposition", "inline;filename="+ System.Convert.ToChar(34) + FileName + System.Convert.ToChar(34) );
refPage.Response.AddHeader("Content-Length", fs.Length.ToString() );
refPage.Response.BinaryWrite( FileData );
fs.Close();
System.IO.File.Delete( _FilePath );
refPage.Response.End();
gawz 2003-11-27
  • 打赏
  • 举报
回复
没办法了吗?
gawz 2003-11-26
  • 打赏
  • 举报
回复
具体一点好吗? 感激不尽!!!
acewang 2003-11-26
  • 打赏
  • 举报
回复
点击按钮将图片读成数据流的方式输出

62,074

社区成员

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

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

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

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