有没有办法下载用户上传的图片?我有以下内容:首先,用户单击马赛克中的图像以详细查看它;然后在asp:image标签中生成图像,在该步骤中,他们应该通过单击按钮来下载图像。我遇到的问题是,图像是在asp:image标记中生成的,而不是带有名称的实际图像本身。我必须下载的代码只获取存储在文件夹中的图像。代码如下:
protected void btnDownload_Click(object sender, EventArgs e)
{
string path = @"C:\inetpub\wwwroot\PSCSearchEngine\MemberPages\Images\live.jpg";
System.IO.FileInfo file = new System.IO.FileInfo(path);
if (file.Exists)
{
Response.Clear();
Response.ContentType = MimeType(Path.GetExtension(path));
Response.AddHeader("Content-Disposition",
string.Format("attachment; filename = {0}",
System.IO.Path.GetFileName(path)));
Response.AddHeader("Content-Length", file.Length.ToString("F0"));
Response.TransmitFile(path);
Response.End();
}
else
{
Response.Write("This file does not exist.");
}
}
下面是预览图片的代码:
@"~/MemberPages/UpdatePhoto.aspx?SiteKey=" + foo.Site_ID
+ "&TimeStamp=" + foo.timestamp[n1 - 1];
发布于 2013-09-07 19:02:57
在C#中使用单击按钮下载图像文件的代码
protected void btnDownload_Click(object sender, EventArgs e)
{
string filename=MapPath("birds.jpg");
Response.ContentType = "image/JPEG";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename+ "");
Response.TransmitFile(filename);
Response.End();
}
发布于 2017-09-02 17:59:36
你可以试试这个:
using (var client = new System.Net.WebClient())
{
var _imagebytes = client.DownloadData(string.Format(@"~/MemberPages/UpdatePhoto.aspx?SiteKey={0}&TimeStamp={1}", foo.Site_ID, foo.timestamp[n1 - 1]));
Response.Clear();
Response.ContentType = "image/jpg";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", "MyImage.jpg"));
Response.AddHeader("Content-Length", _imagebytes.Length.ToString("F0"));
Response.OutputStream.Write(_imagebytes, 0, _imagebytes.Length);
Response.End();
}
https://stackoverflow.com/questions/14899443
复制相似问题