ZipFiles – not that hard, but here are some links to get through what should be super simple

I need to zip files and add a timestamp to the zip filename, or I don’t have a backup system (I just have a copy of the latest files whether or not they are correct). This is TOTALLY related to my article on scripting out my SQL table data contents. This is run as a scheduled task – but I had to take a copy of the solution on my LOCAL drive- not a network copy or else the scheduled tasks does not work. See my article to reduce frustrations on Scheduled Tasks.

Using c# – here is the code snibbet (read the whole article though)

[csharp]</pre>
&nbsp;

if ((machineName = myargs.Item("scripttables")) != null)
{

DateTime filenameTimeStamp = DateTime.Now;
string fileTSstring = filenameTimeStamp.ToString("yyyyMMss_HHmmsstt");
string startPath = Directory.GetCurrentDirectory()+@"\data";// @".";
string zipPath = @"tablesScripted_" + db.Name + "_" + fileTSstring + ".zip";

Console.WriteLine("Completed ONLY scripting the tables and making the archive called ‘" + zipPath + "’");
System.IO.Compression.ZipFile.CreateFromDirectory(startPath, zipPath);

return;
}
<pre>[/csharp]

Before you use this code

You have to reference the following TWO (2!!!!!) dlls and put the “using System.IO.Compression” at the top in this directory. (I did say TWO dll’s right?)

  1. ~/Windows/Microsoft.NET/assembly/GAC_MSIL/System.IO.Compression.FileSystem/(Your .NET Version)/System.IO.Compression.FileSystem.dll
  2. ~/Windows/Microsoft.NET/assembly/GAC_MSIL/System.IO.Compression/(Your .NET Version)/System.IO.Compression.dll