关于文件下载
想做一个文件下载的功能,出现了Bug:
方法一:
fs = new FileStream(filePathName, FileMode.Open, FileAccess.Read);
br = new BinaryReader(fs);
byte[] byteData = br.ReadBytes(Convert.ToInt32(fs.Length));
br.Close();
br = null;
fs.Close();
fs = null;
if (deleteFlg == true)
{
File.Delete(filePathName);
deletedFlg = true;
}
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition",
"attachment; filename=" + HttpUtility.UrlEncode(outputFileName));
Response.BinaryWrite(byteData);
Response.Flush();
Response.End();
这个方法的问题是:根据客户的要求是我已经选择了需要下载到的文件夹的目录下,可是这种方法还要点击保存。。又要重新选择文件夹。能不能实现直接下载到所选定的文件夹中。。
方法2:是使用WebClient的DownLoadFile方法
可是我居然发现这个方法不好用。能下载,但下载到了服务器端。并没有下载到客户端。
方法3就是javascript脚本了。。自己写了一个。。还是不行。。谁还有别的方法?提供一点思路。。