asp.net实现打包程序
2011-11-23 15:36
344 查看
[title3]最近在公司做一个系统,在其中运用到了打包技术。就是把很多文件打包成一个zip文件然后让客户端下载。[/title3]
[title3]以下是主要的代码实现 ,因为博客原因,所需dll请联系我
本人个人网页
using System;
using System.Collections.Generic
using System.Linq;
using System.Web;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using System.Web.SessionState;
namespace WebApplication1
{
public class PackDownLoad
{
//打包临时文件路径
public static string _homeworkCompressedFileLocation = System.Web.Configuration.WebConfigurationManager.AppSettings["downLoadPath"].ToString();
/// <summary>
/// 代理异步download
/// </summary>
public delegate void AsynDownload(string downloadWhat, HttpSessionState session);
/// <summary>
/// 打包下载主方法
/// </summary>
public static void putPack(string zipName, HttpSessionState session)
{
AsynDownload asyn = new AsynDownload(beginDownload);
asyn.BeginInvoke(zipName, session, null, null);
}
/// <summary>
/// 开始打包下载
/// </summary>
/// <param name="downloadWhat"></param>
private static void beginDownload(string zipFileName, HttpSessionState session)
{
try
{
FileStream fileStream = File.Create(Path.Combine(_homeworkCompressedFileLocation, zipFileName));
using (ZipOutputStream s = new ZipOutputStream(fileStream))
{
s.SetLevel(9); // 0-9, 9 being the highest level of compression
foreach (string className in new string[] { "1", "2", "3" })
{
FileStream excelStream = new FileStream(_homeworkCompressedFileLocation + "/ITP1.0需求反馈.xls", FileMode.Open, FileAccess.Read);
ZipEntry excelEntry = new ZipEntry(className + ".xls");
excelEntry.DateTime = DateTime.Now;
s.PutNextEntry(excelEntry);
int fileSize = (int)excelStream.Length;
byte[] bytes = new byte[fileSize];
excelStream.Read(bytes, 0, fileSize);
excelStream.Close();
s.Write(bytes, 0, fileSize);
}
//压缩文件生成了以后,更改session中的值,说明已经转换完成了。
session[zipFileName] = true;
}
}
catch (Exception ex)
{
}
}
}
}[/title3]
相关文章推荐
- ASP.NET MVC实现仪表程序
- ASP.NET程序实现多彩下拉框开发实例解析
- 在ASP.NET AJAX中使用应用程序服务和本地化(2):示例程序:实现用户登录和注销
- 在IIS中改变ASP.NET程序版本的实现方法附批处理代码
- asp.net 计划任务管理程序实现,多线程
- 【EntityFramework系列教程三,翻译】在ASP.NET MVC程序中使用EntityFramework对数据进行排序、过滤筛选以及实现分页
- Asp.net程序注册的完整实现
- ASP.NET 计划任务(不使用外接程序,.net内部机制实现)
- asp.net打包过程详解(WEB程序也能打包)
- 晚上无聊象征性收取了网友100元辛苦费,实现支持多语言功能的XML语言包版的C#的ASP.NET多语言支持例子程序
- 用资源文件实现Asp.net程序的不同语言间的切换
- 自定义ASP.NET AJAX拖放功能示例程序:实现IDragSource和IDropTarget接口将商品拖放至购物车中
- ASP.NET MVC实现仪表程序
- asp.net 程序,单击按钮时 同时实现打开页面并处理值
- asp.net Grid 导出Excel实现程序代码
- asp.net 实现进度条 用来显示加载进度或程序处理进度
- asp.net一般处理程序实现验证码功能
- asp.net(c#)程序版本升级更新的实现代码
- 集成轻量级的IIS实现打包Asp.Net网站生成exe方便快捷的进行客户演示