1.图片地址为url路径 例如:http://home.cnblogs.com/images/ico_question.gif
2.点击 下载图片 超连接下载此图片
3.下载方式 为弹出窗口 提供 打开 保存 取消功能的届面
谢谢 在线等
示例程序:
protected void Page_Load(object sender, EventArgs e)
{
string path=Server.MapPath(@"Images\ico_question.gif");
Open(path);
}
public void Open(string FullFileName)
{
try
{
FileInfo DownloadFile = new FileInfo(FullFileName);
if (DownloadFile.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.ASCII));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
else
{
Response.Write("文件路径有误!");
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
你调用open方法就OK了
这些虚拟路径是不行的 我那个是URL路径
Server.MapPath
FileInfo
这种都是不支持URL格式的
@lbaichun: 换成这样:
protected void Page_Load(object sender, EventArgs e)
{
Open("http://home.cnblogs.com/images/ico_question.gif");
}
public void Open(string FullFileName)
{
Response.AppendHeader("Content-Disposition", "attachment;filename=ico_question.gif");
Response.ContentType = "application/octet-stream";
HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(FullFileName);
HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();
Stream readStream = myWebResponse.GetResponseStream();
int chunkSize = 4096;
byte[] bytes = new byte[chunkSize];
int intBytesRead = readStream.Read(bytes, 0, bytes.Length);
while (intBytesRead > 0)
{
Response.OutputStream.Write(bytes, 0, intBytesRead);
bytes = new byte[chunkSize];
intBytesRead = readStream.Read(bytes, 0, bytes.Length);
}
readStream.Close();
myWebResponse.Close();
}
@天行健 自强不息: 你的问题解决没有啊,如果解决了快点结帖哦^_^
@天行健 自强不息: 谢谢了 下面的方法是可行的 哈哈...