如何在用户不知情的情况下,将一张图片(或者其他文件)下载并保存到客户端? 现在做的一个东西,有一张图片是放在服务器上的,客户端需要用到(有一个ocx控件需要读入一个图片,但是只提供一个本地路径参数),如何在不打扰客户的情况下,将图片下载到客户端,然后把路径传递给这个ocx控件呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string Url = "http://www.baidu.com/img/baidu.gif"; string StringFileName = Url.Substring(Url.LastIndexOf("/") + 1); string StringFilePath = Request.PhysicalApplicationPath; if (!StringFilePath.EndsWith("/")) StringFilePath += "/"; MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass(); _xmlhttp.open("GET", Url, false, null, null); _xmlhttp.send(""); if (_xmlhttp.readyState == 4) { if (System.IO.File.Exists(StringFilePath + StringFileName)) System.IO.File.Delete(StringFilePath + StringFileName); System.IO.FileStream fs = new System.IO.FileStream(StringFilePath + StringFileName, System.IO.FileMode.CreateNew); System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs); w.Write((byte[])_xmlhttp.responseBody); w.Close(); fs.Close(); Response.Write("文件已经得到。<br><a href='" + Request.ApplicationPath + "\\" + StringFileName + "' target='_blank'>"); Response.Write("查看" + StringFileName + "</a>"); } else //Response.Write (_xmlhttp.statusText); Response.End(); 注意要添加 Com引用 Microsoft XML, v2.6 to fellowcheng:你的代码貌似保存在服务器端的吧? decimal问题 PageBase的基类问题 在.net中实现管理菜单的动态性 是谁让我抓狂!!! 在win2003环境下创建asp.net项目的问题 谁的vs2002中捆绑的水晶报表使用正常的话,请把水晶报表的注册ID和密码,还有那个密钥文件(dll),请提供给我,100分!谢谢! 大家帮我看看这是为什么? winServer2003安装为应用服务器,无法运行ASP.NET页,为什为?请帮忙看看这个提示 关于权限控制的问题? 关于DataGrid的问题(在线等待) 制作ASP.NET网站的数据库操作日志 登陆页面跳转后仍是登陆页面
string Url = "http://www.baidu.com/img/baidu.gif";
string StringFileName = Url.Substring(Url.LastIndexOf("/") + 1);
string StringFilePath = Request.PhysicalApplicationPath;
if (!StringFilePath.EndsWith("/")) StringFilePath += "/";
MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
_xmlhttp.open("GET", Url, false, null, null);
_xmlhttp.send("");
if (_xmlhttp.readyState == 4)
{
if (System.IO.File.Exists(StringFilePath + StringFileName))
System.IO.File.Delete(StringFilePath + StringFileName);
System.IO.FileStream fs = new System.IO.FileStream(StringFilePath + StringFileName, System.IO.FileMode.CreateNew);
System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
w.Write((byte[])_xmlhttp.responseBody);
w.Close();
fs.Close();
Response.Write("文件已经得到。<br><a href='" + Request.ApplicationPath + "\\" + StringFileName + "' target='_blank'>");
Response.Write("查看" + StringFileName + "</a>");
}
else
//Response.Write (_xmlhttp.statusText);
Response.End();
你的代码貌似保存在服务器端的吧?