批量下载

lee3217813 2012-11-01 11:07:28
单个下载,搜到了

string fileName = FrameWork.BusinessFacade.GetContractAttachement(long.Parse(s));//客户端保存的文件名
string filePath = Server.MapPath(Common.UpLoadDir + "ContractFiles/" + fileName);//路径

FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();


批量下载怎么弄啊,多了filename
...全文
238 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lee3217813 2012-11-02
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

引用 5 楼 的回复:
http://topic.csdn.net/u/20121015/08/c78078e9-d1a3-4252-b0e3-3d59dc946eca.html?84434
该工具类很全,其中有个SharpZip.cs 注释还行。
随便问答一下lz的问题,RegistryKey 引用一下 Microsoft.Win32就找到

确实很有用,
但是我目前的问题是,选……
[/Quote]

web不能选择下载的文件,只能在服务器指定发送那些文件给用户
zip压缩
文件下载就不说了。不要没看就说看不懂,如果不耐着性子去看,永远也看不懂
lee3217813 2012-11-02
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]
引用楼主 的回复:
单个下载,搜到了

C# code

string fileName = FrameWork.BusinessFacade.GetContractAttachement(long.Parse(s));//客户端保存的文件名
string filePath = Server.MapPath(Common.UpLoadDir + "ContractFiles/……
你……
[/Quote]
那给个有效的方法噻
  • 打赏
  • 举报
回复
可以把多个文件打包处理,然后下载.
net5354 2012-11-01
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
单个下载,搜到了

C# code

string fileName = FrameWork.BusinessFacade.GetContractAttachement(long.Parse(s));//客户端保存的文件名
string filePath = Server.MapPath(Common.UpLoadDir + "ContractFiles/……
[/Quote]你这个下载对下载软件是无效的~~!!
lee3217813 2012-11-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
http://topic.csdn.net/u/20121015/08/c78078e9-d1a3-4252-b0e3-3d59dc946eca.html?84434
该工具类很全,其中有个SharpZip.cs 注释还行。
随便问答一下lz的问题,RegistryKey 引用一下 Microsoft.Win32就找到
[/Quote]
确实很有用,
但是我目前的问题是,选中的文件,
可以把某个文件夹下,选中的文件压缩,然后下载,下载到指定目录,再解压
这个可以实现吗
Ahoo 2012-11-01
  • 打赏
  • 举报
回复
使用 Ionic.Zip.dll 打包单个文件,再输出打包文件。
遊戲王千金 2012-11-01
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20121015/08/c78078e9-d1a3-4252-b0e3-3d59dc946eca.html?84434
该工具类很全,其中有个SharpZip.cs 注释还行。
随便问答一下lz的问题,RegistryKey 引用一下 Microsoft.Win32就找到
lee3217813 2012-11-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
C# code


/// <summary>
/// 压缩文件
/// </summary>
/// <param name="DFilePath">需要压缩的文件夹或者单个文件</param>
/// <param name="DRARName">生成压缩文件的文件名</param>
/// <pa……
[/Quote]
这个注释太少了,没看明白
RegistryKey,ProcessStartInfo 这些都是你自己的类库吧
tptptp00 2012-11-01
  • 打赏
  • 举报
回复

/// <summary>
/// 压缩文件
/// </summary>
/// <param name="DFilePath">需要压缩的文件夹或者单个文件</param>
/// <param name="DRARName">生成压缩文件的文件名</param>
/// <param name="DRARPath">生成压缩文件保存路径</param>
/// <returns></returns>
public static bool RAR(string DFilePath, string DRARName, string DRARPath)
{
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " a " + " " + DRARName + " " + DFilePath + " -ep1"; //命令 + 压缩后文件名 + 被压缩的文件或者路径
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = DRARPath; //RaR文件的存放目录。
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
return true;
}
catch
{
return false;
}
}
public static bool DownLoadFile(string _FilePath, string _FileName,HttpResponseBase Response)
{
try
{
System.IO.FileStream fs = System.IO.File.OpenRead(_FilePath + _FileName);
byte[] FileData = new byte[fs.Length];
fs.Read(FileData, 0, (int)fs.Length);
Response.Clear();
Response.AddHeader("Content-Type", "application/ms-word");
string FileName = System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(_FileName));
Response.AddHeader("Content-Disposition", "inline;filename=" + System.Convert.ToChar(34) + FileName + System.Convert.ToChar(34));
Response.AddHeader("Content-Length", fs.Length.ToString());
Response.BinaryWrite(FileData);
fs.Close();
//删除服务器临时文件
System.IO.File.Delete(_FilePath + _FileName);
Response.Flush();
Response.End();
return true;
}
catch (Exception ex)
{
// ex.Message.ToString();
throw ex;
return false;
}

}
string path =@"D:\\File";
string rarName="aa";
if(RAR(path , rarName, path )){
DownLoadFile(newpath, rarName + ".rar", Response)
}
todototry 2012-11-01
  • 打赏
  • 举报
回复
这是批量上传的例子http://blog.csdn.net/todototry/article/details/8134794
循环逐个下载即可
个人意见,高手多多指教

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧