TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Fatimah Zakaria
NA
2
6.6k
How to set limit size of zip file
Mar 26 2018 9:49 PM
Currently, i have been develop a zip project that need to set a limit size while zipping process and set the process to be auto run smoothly based on the limit size. For example, firstly we must analyze the total size of the data and then set the first file to be zipped as 200GB for the limit space then it will still execute the second file continuously based on the limit size. Can anyone shared idea/solution.
Below are my code.
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.IO;
using
System.Threading;
using
Ionic.Zip;
namespace
Zip_Test
{
public
partial
class
Form1 : Form
{
private
bool
isFolder =
false
;
public
Form1()
{
InitializeComponent();
}
private
void
btn_zip_Click(
object
sender, EventArgs e)
{
if
(
string
.IsNullOrEmpty(txtbox_folder.Text))
{
MessageBox.Show(
"PLEASE SELECT A FOLDER OR FILE TO BE ZIP"
);
return
;
}
else
{
SaveFileDialog sfd =
new
SaveFileDialog();
sfd.InitialDirectory = @
"C:\"
;
sfd.Filter =
"Zip Files|*.zip;*.rar"
;
sfd.FilterIndex = 0;
sfd.RestoreDirectory =
true
;
sfd.Title =
"SAVE ZIP FILE TO"
;
sfd.FileName =
"ZIP FILE "
+ DateTime.Now.ToString(
"dd-MMMM-yyyy hh.mm.ss tt"
);
if
(sfd.ShowDialog() == DialogResult.OK)
{
if
(isFolder ==
true
)
{
//ZipFile.CreateFromDirectory(txt_folderPath.Text, sfd.FileName);
string
path = txtbox_folder.Text;
Thread thread =
new
Thread(t =>
{
using
(Ionic.Zip.ZipFile zip =
new
Ionic.Zip.ZipFile())
{
zip.AddDirectory(path);
System.IO.DirectoryInfo di =
new
System.IO.DirectoryInfo(path);
//zip.SaveProgress += Zip_SaveProgress;
zip.Save(
string
.Format(
"{0}\\{1}.zip"
, di.Parent.FullName, di.Name));
}
}) { IsBackground =
true
};
thread.Start();
}
else
{
string
fileName = txtbox_folder.Text;
Thread thread =
new
Thread(t =>
{
using
(Ionic.Zip.ZipFile zip =
new
Ionic.Zip.ZipFile())
{
FileInfo fi =
new
FileInfo(fileName);
zip.AddFile(fileName);
System.IO.DirectoryInfo di =
new
System.IO.DirectoryInfo(fileName);
//zip.SaveProgress += Zip_SaveFileProgress;
zip.Save(
string
.Format(
"{0}/{1}.zip"
, di.Parent.FullName, di.Name));
}
}) { IsBackground =
true
};
thread.Start();
// string[] files = txt_folderPath.Text.Split(',');
//ZipArchive zip = ZipFile.Open(sfd.FileName, ZipArchiveMode.Create);
// foreach (string file in files)
//{
//zip.CreateEntryFromFile(file, Path.GetFileName(file), CompressionLevel.Optimal);
//}
}
MessageBox.Show(
"ZIP file created successfully!"
);
}
else
{
return
;
}
}
}
private
void
btn_folder_Click(
object
sender, EventArgs e)
{
FolderBrowserDialog fbd =
new
FolderBrowserDialog();
fbd.ShowNewFolderButton =
true
;
if
(fbd.ShowDialog() == DialogResult.OK)
{
btn_reset.Enabled =
true
;
txtbox_folder.Text = fbd.SelectedPath;
isFolder =
true
;
if
(Directory.GetFiles(txtbox_folder.Text).Length > 0)
{
foreach
(
string
file
in
Directory.GetFiles(txtbox_folder.Text))
{
//Add file in ListBox.
listBox1.Items.Add(file);
}
}
//string[] filePaths = Directory.GetFiles(txt_folderPath.Text, "*.*", SearchOption.TopDirectoryOnly);
//for (int i = 0; i < filePaths.Length; i++)
//{
// listBox1.Items.Add(filePaths[i]);
//}
}
else
{
return
;
}
}
private
void
btn_reset_Click(
object
sender, EventArgs e)
{
txtbox_folder.Text =
null
;
listBox1.Items.Clear();
btn_reset.Enabled =
false
;
}
private
void
listBox1_SelectedIndexChanged(
object
sender, EventArgs e)
{
}
}
}
Reply
Answers (
2
)
Close a window about other process opened
How to select random id from database and display randomly o