|
|
|
ทำ Zip file แบบใส่ (Password) พาสเวิร์ดใน C# ยังไงครับ พอดีหาโค๊ดเมืองนอกมีแต่แบบโหลดไลบารี่ เสียตังค์ |
|
|
|
|
|
|
|
ใช้ Component ของอะไรครับ
|
|
|
|
|
Date :
2011-03-25 16:52:27 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้า ICSharpCode.SharpZipLib ใช้แบบนี้ครับ
Code (C#)
public void genZipFile(string filename, string pwd)
{
string zipFileName;
string fileExt;
try
{
fileExt = Path.GetExtension(filename);
zipFileName = filename.Replace(fileExt, ".zip");
using (ZipOutputStream s = new ZipOutputStream(File.Create(zipFileName)))
{
s.Password = pwd;
s.SetLevel(4); // 0 - store only to 9 - means best compression
byte[] buffer = new byte[4096];
ZipEntry entry = new ZipEntry(Path.GetFileName(filename));
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(filename))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
s.Finish();
s.Close();
}
}
catch (Exception ex)
{
Console.WriteLine("Exception during processing {0}", ex);
}
}
|
|
|
|
|
Date :
2011-03-25 16:54:47 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thx ครับ
|
|
|
|
|
Date :
2011-03-28 09:21:48 |
By :
emhumi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|