社区
C#
帖子详情
C#中怎么将文件夹或文件打包下载
a4562834
2011-07-22 06:11:22
我想实现一个下载功能,包含文件夹或文件(jpg、txt格式之类的),请问怎么将他们打包下载啊?
先谢谢了!
...全文
450
13
打赏
收藏
C#中怎么将文件夹或文件打包下载
我想实现一个下载功能,包含文件夹或文件(jpg、txt格式之类的),请问怎么将他们打包下载啊? 先谢谢了!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
13 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
a4550718
2011-12-28
打赏
举报
回复
/// <summary>
/// 文件夹打包方法
/// </summary>
/// <param name="strPath"></param>
/// <param name="strFileName"></param>
protected void dlZipDir(string strPath, string strFileName)
{
MemoryStream ms = null;
Response.ContentType = "application/octet-stream";
strFileName = HttpUtility.UrlEncode(strFileName).Replace('+', ' ');
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName + ".zip");
ms = new MemoryStream();
zos = new ZipOutputStream(ms);
string strBaseDir = Request.PhysicalApplicationPath + strPath;
addZipEntry(strBaseDir);
zos.Finish();
zos.Close();
Response.Clear();
Response.BinaryWrite(ms.ToArray());
Response.End();
}
/// <summary>
/// 文件夹打包方法
/// </summary>
/// <param name="PathStr"></param>
protected void addZipEntry(string PathStr)
{
DirectoryInfo di = new DirectoryInfo(PathStr);
foreach (DirectoryInfo item in di.GetDirectories())
{
addZipEntry(item.FullName);
}
foreach (FileInfo item in di.GetFiles())
{
FileStream fs = File.OpenRead(item.FullName);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
string strEntryName = item.FullName.Replace(PathStr, "");
string fileName = strEntryName.Substring(strEntryName.LastIndexOf("\\") + 1);
ZipEntry entry = new ZipEntry(fileName);
zos.PutNextEntry(entry);
zos.Write(buffer, 0, buffer.Length);
fs.Close();
}
}
a4550718
2011-12-28
打赏
举报
回复
/// <summary>
/// 文件夹打包方法
/// </summary>
/// <param name="strPath"></param>
/// <param name="strFileName"></param>
protected void dlZipDir(string strPath, string strFileName)
{
MemoryStream ms = null;
Response.ContentType = "application/octet-stream";
strFileName = HttpUtility.UrlEncode(strFileName).Replace('+', ' ');
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName + ".zip");
ms = new MemoryStream();
zos = new ZipOutputStream(ms);
string strBaseDir = Request.PhysicalApplicationPath + strPath;
addZipEntry(strBaseDir);
zos.Finish();
zos.Close();
Response.Clear();
Response.BinaryWrite(ms.ToArray());
Response.End();
}
/// <summary>
/// 文件夹打包方法
/// </summary>
/// <param name="PathStr"></param>
protected void addZipEntry(string PathStr)
{
DirectoryInfo di = new DirectoryInfo(PathStr);
foreach (DirectoryInfo item in di.GetDirectories())
{
addZipEntry(item.FullName);
}
foreach (FileInfo item in di.GetFiles())
{
FileStream fs = File.OpenRead(item.FullName);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
string strEntryName = item.FullName.Replace(PathStr, "");
string fileName = strEntryName.Substring(strEntryName.LastIndexOf("\\") + 1);
ZipEntry entry = new ZipEntry(fileName);
zos.PutNextEntry(entry);
zos.Write(buffer, 0, buffer.Length);
fs.Close();
}
}
小阳
2011-07-29
打赏
举报
回复
[Quote=引用 7 楼 weike021996 的回复:]
gogogo
[/Quote]
这个好像还不错!
AK47
2011-07-29
打赏
举报
回复
good good study,day day up!
viki117
2011-07-29
打赏
举报
回复
关键看服务段,ZIP网上大把类库..
小驴来这里学习
2011-07-28
打赏
举报
回复
mark
weike021996
2011-07-24
打赏
举报
回复
gogogo
zjq8888882009
2011-07-24
打赏
举报
回复
百度搜,压缩,解压类,一搜一大堆。
ljjhw320
2011-07-23
打赏
举报
回复
你先进行打包了,再进行下载就可以啊!
a4562834
2011-07-23
打赏
举报
回复
具体的给点代码吧,谢谢了!
极地_雪狼
2011-07-22
打赏
举报
回复
调用winrar或zip的api接口
sugarbelle
2011-07-22
打赏
举报
回复
服务器端要支持压缩包功能...
你搜zip 命令压缩..或者rar压缩..很简单的,就和ping 网址一样.
xixihaha_2011_098
2011-07-22
打赏
举报
回复
用winrar或者winzip 命令行。打包,然后通过地址就可以下载吧
C#
文件
及
文件
夹
自动
打包
程序
程序根据
文件
及
文件
夹
自动
打包
成.RAR格式
C#
用递归的方式查找指定
文件
夹
下的所有子目录
C#
用递归的方式查找指定
文件
夹
下的所有子目录,
C#
代码 采用递归的方法來查找指定
文件
夹
及它的所有子
文件
夹
裏的内容。
C#
程序
打包
成EXE
文件
的工具
可以把
C#
工程转成可以直接运行的EXE
文件
,使用时把你
C#
工程
中
的bin\debug
文件
夹
下面的
文件
导入,然后生成exe
文件
即可,生成的
文件
会遭到杀毒软件报警,提醒用户,在杀毒软件
中
添加信任即可。
LZMA
C#
SDK 结合 UPK
打包
多
文件
夹
Unity3d实例
LZMA
C#
SDK 结合 UPK
打包
多
文件
夹
Unity3d实例
C#
添加
文件
夹
打包
测试程序
摘要:
C#
源码,
文件
操作,
文件
夹
打包
C#
添加
文件
夹
打包
测试程序,
文件
夹
打包
测试程序源码
下载
,
C#
新手的一个参考源码,对学习
C#
有帮助。
C#
110,538
社区成员
642,577
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章