using
system;
using
system.collections.generic;
using
system.io;
using
icsharpcode.sharpziplib.zip;
namespace
testconsole
///
/// 壓縮檔案為zip包
///
///
///
private
static
bool
createzipfile(
string
filespath,
string
zipfilepath)
trywhile
(sourcebytes > 0);
} }
s.finish();
s.close();
} return
true
; }
catch
(exception ex)
", ex);
} return
false
; }
///
/// 檔案解壓(zip格式)
///
///
///
private
static
listunzipfile(
string
zipfilepath)
using
(var zipinputstream =
newzipinputstream(file.openread(zipfilepath)))
} if(!
string
.isnullorempty(filename))
else
} } files.add(new
fileinfo(filepath));
} }
} }
} return
files;
} }
}
[csharp]view plain
copy
print?
///
/// 檔案解壓(rar格式)
///
///
///
public
static
listunrarfile(
string
rarfilepath)
} dirname = dirname.endswith("\\") ? dirname : dirname + "
\\";
//最後這個斜槓不能少!
string
shellarguments =
string
.format(
"x -o+ "
, rarfilepath, dirname);
using
(var unrar =
newprocess())
var dir = new
directoryinfo(dirname);
files.addrange(dir.getfiles());
} return
files;
}
[csharp]view plain
copy
print?
/ / 檔案解壓2(rar格式)使用sharpcompress元件 需.net 3.5以上才支援!
/ /
/ //private static listunrarfile(string rarfilepath)
//// }
// while (reader.movetonextentry())
//
// }
// }
// }
// }
// return files;
//}///
/// 解壓功能(解壓壓縮檔案到指定目錄)
///
/// 待解壓的檔案
/// 指定解壓目標目錄
/// 密碼
/// 解壓結果
public static bool chargeunzip(string filetounzip, string zipedfolder, string password)
fs= new filestream(filename, filemode.openorcreate,fileaccess.readwrite,fileshare.readwrite);
int size = 2048;
byte data = new byte[size];
size = zipstream.read(data, 0, data.length);
if (size > 0)
else
break;}}
}catch
finally
if (zipstream != null)
if (ent != null)
fs.flush();
fs.close();
gc.collect();
gc.collect(1);
}return result;
}///
/// 解壓功能(解壓壓縮檔案到指定目錄)
///
/// 待解壓的檔案
/// 指定解壓目標目錄
/// 解壓結果
public static bool chargeunzip1(string filetounzip, string zipedfolder)
檔案上傳壓縮包並解壓
index.html up.php require once zip.php header content type text html charset utf 8 periodsdate post periodsdate periodsdate b dir getcwd path dir.ups ...
C 檔案流壓縮解壓
檔案流壓縮解壓 public class ziphelper deflate方式壓縮 壓縮品質級別 0 9 public static stream deflate stream stream,int level deflate方式壓縮 壓縮品質級別 0 9 public static byte d...
C 壓縮解壓Zip檔案
新增引用icsharpcode.sharpziplib.dll region 加壓方法 被壓縮的資料夾夾路徑 生成壓縮檔案的路徑,為空則預設與被壓縮資料夾同一級目錄,名稱為 資料夾名 zip 出錯資訊 是否壓縮成功 public static bool zipfile string dirpath,...