Hi All,

I Need C# Code to Compress KMZ file.

Below is a piece of code which is used to save Datagrid data to KMZ.
But I need code to compress KMZ .
Thanks for your help in advance.




/// <summary>
/// This function brings up a SaveFileDialog to offer the user a choice in naming
/// the file that is to be saved.
/// </summary>
private void SaveFileAsKMZ()
{
try
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.OverwritePrompt = false;
sfd.Filter = "Subdivision documents (*.kmz)|*.kmz";
sfd.Title = "Save Subdivision File As kmz";
sfd.InitialDirectory = DefaultSubdivDirectory;

SaveDefaultDirectoryLocation( sfd.FileName );
DialogResult dr = sfd.ShowDialog();
if( dr == DialogResult.OK )
{
if( File.Exists( sfd.FileName ) )
{
dr = MessageBox.Show(
"The file already exists.\n" +
"Overwrite or not?",
"File Exists!",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Asterisk );
}
if( dr == DialogResult.OK )
{
TrackTopologyFile topo = TopoFile;
KMZWriter writer = new KMZWriter( topo );
writer.DefaultDirectory = DefaultSubdivDirectory;

string sFileName = sfd.FileName;

bool bOk = writer.SaveAsKMZAdvanced( sFileName );

if( bOk )
{

MessageBox.Show(
"The following file was saved: \n" + sFileName,
"Saved!",
MessageBoxButtons.OK,
MessageBoxIcon.Information );
}
else
{
MessageBox.Show(
"An error occurred!\n" +
"The following file was NOT saved: \n" + sFileName,
"ERROR!",
MessageBoxButtons.OK,
MessageBoxIcon.Error );
}
}
}
}