C# asp.net在单击图像时自动下载图像
我是asp.net新手,想知道或是一个关于如何点击图片自动下载图片的代码示例。我的图像是动态生成的。这是从代码隐藏中生成图像的代码C# asp.net在单击图像时自动下载图像,c#,asp.net,C#,Asp.net,我是asp.net新手,想知道或是一个关于如何点击图片自动下载图片的代码示例。我的图像是动态生成的。这是从代码隐藏中生成图像的代码 foreach (HtmlNode n in nodes) { string img = n.InnerHtml; if (n.InnerHtml.Contains(" ")) { img = n.InnerHtml.Replace(" ", "%20"); } count++; if (co
foreach (HtmlNode n in nodes)
{
string img = n.InnerHtml;
if (n.InnerHtml.Contains(" ")) { img = n.InnerHtml.Replace(" ", "%20"); }
count++;
if (count == 1) {
newhtml = "<img src =http://img.crwd.io/" + img+" width=\"320px\">";
table.Rows.Add(new TableRow());
table.Rows[row].Cells.Add(new TableCell());
table.Rows[row].Cells.Add(new TableCell());
table.Rows[row].Cells.Add(new TableCell());
table.Rows[row].Cells.Add(new TableCell());
table.Rows[row].Cells[0].Text = newhtml;
}
else if (count == 4) {
newhtml = "<img src =http://img.crwd.io/" + img + " width=\"320px\">";
table.Rows[row].Cells[3].Text = newhtml;
count = 0;
row++; }
else if (count == 3) {
newhtml = "<img src =http://img.crwd.io/" + img + " width=\"320px\">";
table.Rows[row].Cells[2].Text = newhtml; }
else if (count == 2) {
newhtml = "<img src =http://img.crwd.io/" + img + " width=\"320px\">";
table.Rows[row].Cells[1].Text = newhtml; }
}
foreach(节点中的HtmlNode n)
{
字符串img=n.InnerHtml;
如果(n.InnerHtml.Contains(“”){img=n.InnerHtml.Replace(“,“%20”);}
计数++;
如果(计数=1){
newhtml=“”;
table.Rows.Add(newtablerow());
table.Rows[row].Cells.Add(new TableCell());
table.Rows[row].Cells.Add(new TableCell());
table.Rows[row].Cells.Add(new TableCell());
table.Rows[row].Cells.Add(new TableCell());
table.Rows[row]。单元格[0]。Text=newhtml;
}
否则如果(计数=4){
newhtml=“”;
table.Rows[row]。单元格[3]。Text=newhtml;
计数=0;
行+++;}
如果(计数=3){
newhtml=“”;
table.Rows[row]。单元格[2]。Text=newhtml;}
如果(计数=2){
newhtml=“”;
table.Rows[row]。单元格[1]。Text=newhtml;}
}
我想当图像被点击时,它会自动从用户下载到一个特定的位置,如果可能的话。谢谢。只要给他们一个链接:
var url = string.Format("http://img.crwd.io/{0}", img);
newhtml = string.Format("<a href=\"{0}\" target=\"_blank\">" +
"<img src=\"{0}\" width=\"320px\"></a>", url);
var url=string.Format(“http://img.crwd.io/{0},img);
newhtml=string.Format(“,url”);
如果您这样做,浏览器将为您处理一切
更新:根据下面的评论,需要创建ActiveX控件。嘿,伙计,我的意思是,当用户单击任何图像时,它将自动下载。只是自动的,没有其他功能..谢谢:)@Wylan,没有ActiveX控件,这是不可能的,而且只能在IE中工作。而且,坦白说,这是不安全的。浏览器的任务是保护用户不受您所解释的内容的影响。实际上,这没关系,因为它受密码保护。任何用户都看不到或无法访问它,只有团队(我们)。@WylanOsorio,那么您需要构建一个ActiveX控件;这只适用于IE。加载ActiveX控件时,它将请求访问机器,然后您可以直接访问C#可以运行的任何内容。