上传到服务器上的压缩包如何解压
上传到服务器上的压缩包如何解压 --------------------编程问答-------------------- 服务端调用winrar的命令行版本rar.exe进行解压或其他压缩软件的命令行版本,当然要带参数。服务端要有执行exe文件的权限。 --------------------编程问答-------------------- http://www.cnblogs.com/zhaozhan/archive/2012/05/28/2520701.html我是自压自解用的是System.IO.Packaging,其它的没试过 --------------------编程问答--------------------
+++这个可以有 --------------------编程问答-------------------- 楼主问的是程序解压还是自己解压呢?程序如楼上所说,如果自己解压..... --------------------编程问答-------------------- 在服务器那头自己解压吧!但是得有权限撒 --------------------编程问答-------------------- 服务器端得有程序控制,然后用改命令解压
--------------------编程问答--------------------
System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
Process1.StartInfo.FileName = "Winrar.exe";
Process1.StartInfo.CreateNoWindow = true;
Process1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process1.StartInfo.Arguments = "x " + filepath + "\\" + SendFileName + " " + s + " -y";
Process1.Start();
--------------------编程问答-------------------- http://www.icsharpcode.net/opensource/sharpziplib/
UnZipFile(MapPath("~/NEWAGE.zip"), MapPath("~/"), out strErro)
#region 解压实现更新
/// <summary>
/// 功能:解压zip格式的文件。
/// </summary>
/// <param name="zipFilePath">压缩文件路径</param>
/// <param name="unZipDir">解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param>
/// <param name="err">出错信息</param>
/// <returns>解压是否成功</returns>
public static bool UnZipFile(string zipFilePath, string unZipDir, out string err)
{
err = "";
if (zipFilePath == string.Empty)
{
err = "压缩文件不能为空!";
return false;
}
if (!File.Exists(zipFilePath))
{
err = "压缩文件不存在!";
return false;
}
//解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹
if (unZipDir == string.Empty)
unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath));
if (!unZipDir.EndsWith("//"))
unZipDir += "//";
if (!Directory.Exists(unZipDir))
Directory.CreateDirectory(unZipDir);
try
{
using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFilePath)))
{
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
if (directoryName.Length > 0)
{
Directory.CreateDirectory(unZipDir + directoryName);
}
if (!directoryName.EndsWith("//"))
directoryName += "//";
if (fileName != String.Empty)
{
using (FileStream streamWriter = File.Create(unZipDir + theEntry.Name))
{
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
}
}
}//while
}
}
catch (Exception ex)
{
err = ex.Message;
return false;
}
return true;
}
//解压结束
#endregion 解压实现更新
本人都是用 sharpziplib 做的 --------------------编程问答-------------------- 如果是zip格式的,这个.net有对应的类库,
如果是其他例如rar的压缩文件,这个需要你的服务器安装了解压工具才行。 --------------------编程问答-------------------- LZ该结贴了。。。。。。。
补充:.NET技术 , ASP.NET