我从数据库中取得文件路径,循环将其打包压缩成zip或rar(多个文件),当压缩包不存在的时候新建压缩包,如果此压缩包已经存在则将要压缩的文件压缩进此压缩包,请问各位大虾,如何实现?注意是要将多个文件一个一个的压缩进一个压缩包中。
解决方案 »
- 获取旺旺窗口的"发送"按钮句柄 100分
- [wcf] “System.ServiceModel.DiagnosticUtility”的类型初始值设定项引发异常。
- 关于DataGridView SelectionChanged
- C#中打开对话窗口,如何做到关闭这个窗口后再执行后面代码?
- 求一份VS2005用serialport类发短信的实例!!
- c#与windows主题!
- c#做一个简单的视频播发器 都用什么控件啊
- ~~~~~~~~~~~高分相送向牛人索取NetAdvantage源码,最好有笔记、注释,
- 如何调用arraylist数组中的变量的成员变量?
- 网页和Word文档的缩略图如何实现?
- xml添加节点提示错误:此文档已具有“DocumentElement”节点
- WinForm检测用户是否已登陆的方法--简单问题--请高手回答!
详细用法在winRAR安装目录下面的Rar.txt中
/// <summary>目录strSrc到指定目录strDest
///
/// </summary>
/// <param name="strSrc">导出的目录</param>
/// <param name="strDest">指定的目录</param>
public string Rar(string strSrc, string strDest)
{
Process p = new Process();
string cmd = String.Format("a -en -ep1 {0} {1} ", "\"" + strDest + "\"", "\"" + strSrc + "\"");
string cmd1 = String.Format("a -en -ap{0} -ep {1}", "新的文件", "\"" + strDest + "\"");
try
{
for (int k = 0; k < 2; k++)
{
p.StartInfo.FileName = Application.StartupPath + "\\Rar.exe";
if (k == 0)
{
p.StartInfo.Arguments = cmd;
}
else
{ for (int i = 0; i < 3; i++)
{
if (TestG[i] != null)
{
if (TestG[i].Paper != null)
{
cmd1 = cmd1 + " \"" + 文件 + "\"";
for (int j = 0; j < Count; j++)
{
if (TestG[i].Paper.part(i) != null)
{ cmd1 = cmd1 + " \"" + 文件 + "\""; }
}
}
}
}
} p.StartInfo.Arguments = cmd1;
}
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
p.WaitForExit();
p.Close(); }
if (Directory.Exists(Application.StartupPath + "\\Temp"))
{
Directory.Delete(Application.StartupPath + "\\Temp", true);
}
return "压缩完成";
}
catch (Exception)
{
return "压缩失败";
}需要windows里的RAR.exe文件 拷贝到工程中
private void Export(string meetingTitle, ref ArrayList fileArray)
{
string pathRoot = Server.MapPath("/");
string winRAR = pathRoot + "meeting/WinRAR/WinRAR.exe";
string vfolder = "/upload/meeting/rar/";
string rarfolder = Server.MapPath("~" + vfolder); //添加文件
StringBuilder file = new StringBuilder();
for (int i = 0; i < fileArray.Count; i++)
{
file.Append("\"" + Tool.CStr(fileArray[i]) + "\" ");
} if (!Directory.Exists(rarfolder))
Directory.CreateDirectory(rarfolder); string makedFile = "\"" + rarfolder + meetingTitle + ".rar\""; if (File.Exists(makedFile) == true)
{
try
{
File.Delete(makedFile);
}
catch
{
Tool.OpenWindow("文件无法删除,请先手动删除!");
}
} string arguments = @"a " + makedFile + " " + file; if (file.Length > 0)
{
try
{
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = winRAR; //winRAR目录
info.Arguments = arguments; //参数
info.WorkingDirectory = pathRoot; Process p = new Process();
p.StartInfo = info;
p.Start(); //启动
p.WaitForExit(); //无限期等待进程退出
p.Close(); //写入数据库
string thisHost = Request.Url.ToString();
thisHost = thisHost.Substring(thisHost.IndexOf("//") + 2);
thisHost = thisHost.Substring(0, thisHost.IndexOf("/"));
thisHost = "http://" + thisHost;
BLL.Meeting.ExportRar er = new BLL.Meeting.ExportRar();
er.Add(_meetingID, meetingTitle, (thisHost + vfolder + meetingTitle + ".rar"), Tool.Cint(Session["AdminID"]));
}
catch (Exception e)
{
Tool.OpenWindow("压缩失败!");
}
//删除生成的附件
for (int i = 0; i < fileArray.Count; i++)
{
try
{
File.Delete(Tool.CStr(fileArray[i]));
}
catch
{ }
}
}
else
{
Tool.OpenWindow("没有需要压缩的文件!");
return;
}
}