Click here to Skip to main content
15,949,686 members
Home / Discussions / C#
   

C#

 
Questionhow start menu name will changed Pin
Surjeet Singh Sidhu22-Mar-07 3:51
Surjeet Singh Sidhu22-Mar-07 3:51 
AnswerRe: how start menu name will changed Pin
Pete O'Hanlon22-Mar-07 4:25
mvePete O'Hanlon22-Mar-07 4:25 
AnswerRe: how start menu name will changed Pin
Thomas Stockwell22-Mar-07 8:00
professionalThomas Stockwell22-Mar-07 8:00 
QuestionHow to delete a file that is used Pin
Ollie198622-Mar-07 3:37
Ollie198622-Mar-07 3:37 
AnswerRe: How to delete a file that is used Pin
Stefan Troschuetz22-Mar-07 3:58
Stefan Troschuetz22-Mar-07 3:58 
GeneralRe: How to delete a file that is used Pin
Ollie198622-Mar-07 4:01
Ollie198622-Mar-07 4:01 
GeneralRe: How to delete a file that is used Pin
Christian Graus22-Mar-07 4:02
protectorChristian Graus22-Mar-07 4:02 
GeneralRe: How to delete a file that is used Pin
Ollie198622-Mar-07 4:04
Ollie198622-Mar-07 4:04 
I don't think so everything is closed:




using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Threading;
using log4net;
using ICSharpCode.SharpZipLib.Zip;
using System.Collections;
using System.Collections.Specialized;

namespace InterfaceCollector.domain.DAL
{
class Zip
{
private string destination;
private readonly ILog log = LogManager.GetLogger(typeof(Zip));
static Hashtable excludeDirs = new Hashtable();
static string startFolder = String.Empty;
static string outputZipPath = String.Empty;
static string password = String.Empty;

public Zip() {}
static private Zip instance = null;
static public Zip Instance
{
get
{
if (instance == null)
instance = new Zip();
return instance;
}
}

public void ZipIt(string Path,string password)
{
log4net.LogManager.Shutdown();
try
{

ArrayList ar = GenerateFileList(Path); // generate file list
// find number of chars to remove from orginal file path
int TrimLength = (Directory.GetParent(Path)).ToString().Length;
TrimLength += 1; //remove '\'
FileStream ostream = null;
byte[] obuffer;
ZipOutputStream oZipStream = new ZipOutputStream(System.IO.File.Create(Destination)); // create zip stream
if (password != String.Empty) oZipStream.Password = password;
oZipStream.SetLevel(9); // 9 = maximum compression level
ZipEntry oZipEntry;

DateTime timeStap = DateTime.Now;
string output = "";
int lenghtWrittenString = 0;
double percent = 1;
int countFiles = 0;
foreach (string Fil in ar) // for each file, generate a zipentry
{
countFiles++;
percent = countFiles * 100 / ar.Count;
//Display % on progressScreen
if (timeStap <= DateTime.Now)
{
timeStap = DateTime.Now.AddMilliseconds(1000);
ApplicationDirector.Instance.removeCharachtersFromProgressScreen(lenghtWrittenString);
if (percent < 100.0)
{
output = "\r\nCreating zip-file (" + percent + "%)";
ApplicationDirector.Instance.writeToGui(output);
}
lenghtWrittenString = output.Length;
}

oZipEntry = new ZipEntry(Fil.Remove(0, TrimLength));
oZipStream.PutNextEntry(oZipEntry);

if (!Fil.EndsWith(@"/")) // if a file ends with '/' its a directory
{
ostream = File.OpenRead(Fil);
obuffer = new byte[ostream.Length]; // byte buffer
ostream.Read(obuffer, 0, obuffer.Length);
oZipStream.Write(obuffer, 0, obuffer.Length);
}
}
ApplicationDirector.Instance.removeCharachtersFromProgressScreen(lenghtWrittenString);
ApplicationDirector.Instance.writeToGui("\r\nCreating zip-file (Completed)");
oZipStream.Finish();
oZipStream.Close();
}
catch (Exception ex)
{
ApplicationDirector.Instance.writeToGui("Error during zipping.");
Logger.Instance.ExtraInfo.Add("Zip-File nog created" + ex);
}
}
private static ArrayList GenerateFileList(string Dir)
{
ArrayList mid = new ArrayList();
bool Empty = true;
foreach (string file in Directory.GetFiles(Dir)) // add each file in directory
{
mid.Add(file);
Empty = false;
}

if (Empty)
{
if (Directory.GetDirectories(Dir).Length == 0) // if directory is completely empty, add it
{
mid.Add(Dir + @"/");
}
}
foreach (string dirs in Directory.GetDirectories(Dir)) // do this recursively
{
// set up the excludeDir test
string testDir = dirs.Substring(dirs.LastIndexOf(@"\") + 1).ToUpper();
if (excludeDirs.Contains(testDir))
continue;
foreach (object obj in GenerateFileList(dirs))
{
mid.Add(obj);
}
}
return mid; // return file list
}

public string Destination
{
get { return destination; }
set
{
string path = Path.GetDirectoryName(value);
path = path + "Agfa Zip - "+Path.GetFileNameWithoutExtension(value) + "\\" + Path.GetFileName(value);
destination = path;
Directory.CreateDirectory(Path.GetDirectoryName(destination));
}
}
}
}
GeneralRe: How to delete a file that is used Pin
Ollie198622-Mar-07 4:06
Ollie198622-Mar-07 4:06 
GeneralRe: How to delete a file that is used Pin
Christian Graus22-Mar-07 4:08
protectorChristian Graus22-Mar-07 4:08 
GeneralRe: How to delete a file that is used Pin
Ollie198622-Mar-07 4:14
Ollie198622-Mar-07 4:14 
GeneralRe: How to delete a file that is used Pin
Christian Graus22-Mar-07 4:51
protectorChristian Graus22-Mar-07 4:51 
GeneralRe: How to delete a file that is used Pin
Ollie198622-Mar-07 4:52
Ollie198622-Mar-07 4:52 
GeneralRe: How to delete a file that is used Pin
Christian Graus22-Mar-07 5:04
protectorChristian Graus22-Mar-07 5:04 
AnswerRe: How to delete a file that is used Pin
Vasudevan Deepak Kumar22-Mar-07 5:42
Vasudevan Deepak Kumar22-Mar-07 5:42 
GeneralRe: How to delete a file that is used Pin
Ollie198622-Mar-07 6:46
Ollie198622-Mar-07 6:46 
Questiondeleting from a parent record that has child records Pin
Rocky#22-Mar-07 3:35
Rocky#22-Mar-07 3:35 
AnswerRe: deleting from a parent record that has child records Pin
sureshmyway22-Mar-07 3:57
sureshmyway22-Mar-07 3:57 
GeneralRe: deleting from a parent record that has child records Pin
Pete O'Hanlon22-Mar-07 4:27
mvePete O'Hanlon22-Mar-07 4:27 
GeneralRe: deleting from a parent record that has child records Pin
Jabeerbe22-Mar-07 4:38
Jabeerbe22-Mar-07 4:38 
GeneralRe: deleting from a parent record that has child records Pin
Pete O'Hanlon22-Mar-07 5:18
mvePete O'Hanlon22-Mar-07 5:18 
GeneralRe: deleting from a parent record that has child records Pin
Rocky#23-Mar-07 0:40
Rocky#23-Mar-07 0:40 
GeneralRe: deleting from a parent record that has child records Pin
Rocky#23-Mar-07 1:14
Rocky#23-Mar-07 1:14 
GeneralRe: deleting from a parent record that has child records Pin
Pete O'Hanlon23-Mar-07 2:37
mvePete O'Hanlon23-Mar-07 2:37 
Questionscroll the form when draw in it Pin
merwa22-Mar-07 3:26
merwa22-Mar-07 3:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.