求解!!!比如传一张图片 1.jpg 然后自动打包成 1.rar 这个如何搞??
解决方案 »
- gridview控件上状态属性字段用背景颜色来代替其在数据库表中的颜色字段
- sqlcommand.ExecuteNonQuery()的返回值问题
- 在VS2005中运行正常,但发布到IIS6.0下就出现乱码
- 我用C# asp.net 做数据显示 由于每条数据都很多 DataGrid 竖行显示怎么改横行啊郁闷......
- ****各位进来指导下小弟学习asp.net***分是大大的有的!
- 请问:?用什么 编辑控件可以将新闻的内容以html形式保存在数据库中,而后在显示页又以原来输入格式输出在页面上呢
- repeater可以设置显示两列吗??
- 请问vs.net2003自带的水晶报表支持WEB打印吗?
- datagrid送分问题
- ASP.NET到底有那些版本,具体有那些主要不同之处?
- Webbrower控件里的页面,想刷新让页面的cookie失效,
- 新手,各位大侠帮帮忙,指教指教呀~~~
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using System.Collections.Generic; private bool Zip(string strZipPath, string strZipTopDirectoryPath, int intZipLevel, string strPassword, string[] filesOrDirectoriesPaths)
{
try
{
List<string> AllFilesPath = new List<string>();
if (filesOrDirectoriesPaths.Length > 0) // get all files path
{
for (int i = 0; i < filesOrDirectoriesPaths.Length; i++)
{
if (File.Exists(filesOrDirectoriesPaths[i]))
{
AllFilesPath.Add(filesOrDirectoriesPaths[i]);
}
else if (Directory.Exists(filesOrDirectoriesPaths[i]))
{
GetDirectoryFiles(filesOrDirectoriesPaths[i], AllFilesPath);
}
}
} if (AllFilesPath.Count > 0)
{ ZipOutputStream zipOutputStream = new ZipOutputStream(File.Create(strZipPath));
zipOutputStream.SetLevel(intZipLevel);
zipOutputStream.Password = strPassword; for (int i = 0; i < AllFilesPath.Count; i++)
{
string strFile = AllFilesPath[i].ToString();
try
{
if (strFile.Substring(strFile.Length - 1) == "") //folder
{
string strFileName = strFile.Replace(strZipTopDirectoryPath, "");
if (strFileName.StartsWith(""))
{
strFileName = strFileName.Substring(1);
}
ZipEntry entry = new ZipEntry(strFileName);
entry.DateTime = DateTime.Now;
zipOutputStream.PutNextEntry(entry);
}
else //file
{
FileStream fs = File.OpenRead(strFile); byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length); string strFileName = strFile.Replace(strZipTopDirectoryPath, "");
if (strFileName.StartsWith(""))
{
strFileName = strFileName.Substring(0);
}
ZipEntry entry = new ZipEntry(strFileName);
entry.DateTime = DateTime.Now;
zipOutputStream.PutNextEntry(entry);
zipOutputStream.Write(buffer, 0, buffer.Length); fs.Close();
fs.Dispose();
}
}
catch
{
continue;
}
} zipOutputStream.Finish();
zipOutputStream.Close(); return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
//调用:
protected void Button1_Click(object sender, EventArgs e)
{
//string ph=Server.MapPath("~/zip");
//dlZipDir(ph, "1");
//Label1.Text = ph; string strZipPath = Server.MapPath("~/zip/1.zip");//生成压缩文件路径和文件名
string strZipTopDirectoryPath = Server.MapPath("~/zip");//源文件的上级目录
int intZipLevel = 6;//压缩等级
string strPassword = "";//压缩包解压密码
string[] filesOrDirectoriesPaths = new string[] { Server.MapPath("~/zip/1.jpg") };//源文件路径
Zip(strZipPath, strZipTopDirectoryPath, intZipLevel, strPassword, filesOrDirectoriesPaths);
}
2、如果多个图片打包用8楼的方法