1. Create a folder in c drive or any drive to any name like i have create a folder the name of path in c drive.
create a text file .
write this code on button_click
string strFile = @"C:\\path\\Create_Zip.bat";
File.Create(strFile).Close();
StreamWriter sw = new StreamWriter(strFile);
string strLine = "";
strLine = " set FILETOZIP= C:\\path\\demo.txt";
sw.WriteLine(strLine);
strLine = " set TEMPDIR=C:\\path\\Temp_Zip;
sw.WriteLine(strLine);
strLine = " rmdir %TEMPDIR%";
sw.WriteLine(strLine);
strLine = " mkdir %TEMPDIR%";
sw.WriteLine(strLine);
strLine = " copy %FILETOZIP% %TEMPDIR%";
sw.WriteLine(strLine);
sw.WriteLine("");
strLine = " echo Set objArgs = WScript.Arguments > _zipIt.vbs";
sw.WriteLine(strLine);
strLine = " echo InputFolder = objArgs(0) >> _zipIt.vbs";
sw.WriteLine(strLine);
strLine = " echo ZipFile = objArgs(1) >> _zipIt.vbs";
sw.WriteLine(strLine);
strLine = " echo CreateObject(\"Scripting.FileSystemObject\").CreateTextFile(ZipFile, True).Write \"PK\" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs";
sw.WriteLine(strLine);
strLine = " echo Set objShell = CreateObject(\"Shell.Application\") >> _zipIt.vbs";
sw.WriteLine(strLine);
strLine = " echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs";
sw.WriteLine(strLine);
strLine = " echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs";
sw.WriteLine(strLine);
strLine = " echo wScript.Sleep 2000 >> _zipIt.vbs";
sw.WriteLine(strLine);
sw.WriteLine("");
strLine = " CScript _zipIt.vbs %TEMPDIR% C:\\path\\abc.zip";
sw.WriteLine(strLine);
sw.WriteLine("");
sw.Close();
sw.Dispose();
int ExitCode;
ProcessStartInfo ProcessInfo;
Process Proc;
ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + strFile);
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = false;
Proc = Process.Start(ProcessInfo);
Proc.WaitForExit();
ExitCode = Proc.ExitCode;
Proc.Close();
File.Delete(strFile);
File.Delete("C:\\path\\\_zipIt.vbs");
Directory.Delete("C:\\path\\Temp_Zip", true);
No comments:
Post a Comment