title: how to compress and uncompress a text file
body: <p>I am having two problems </p>
  
  <p>My problems are </p>
  
  <ol>
  <li>My file name is  20110505.txt  , and  it is compressing a zip file name as  ->   20110505.txt.zip
  But I need  after compressing   this  file   20110505.txt   as -->    20110505.zip only.</li>
  </ol>
  
  <p>I am using this dll</p>
  
  <p>using System.IO.Compression;</p>
  
  <p>Here is my code for compress,</p>
  
  <p>1)is my text format</p>
  
  <pre><code>            string path = DayDestination + "\\" + txtSelectedDate.Text + ".txt";
              StreamWriter Strwriter = new StreamWriter(path);
              DirectoryInfo di = new DirectoryInfo(path);
              FileInfo fi = new FileInfo(path);
              Compress(fi);
  
     public static void Compress(FileInfo fi) 
  { 
      // Get the stream of the source file. 
      using (FileStream inFile = fi.OpenRead()) 
      {
  
          // Prevent compressing hidden and already compressed files. 
          if ((File.GetAttributes(fi.FullName) &amp; FileAttributes.Hidden) 
                  != FileAttributes.Hidden &amp; fi.Name != ".zip") 
          { 
              // Create the compressed file. 
             using (FileStream outFile = File.Create(fi.FullName + ".zip"))
  
              //using (FileStream outFile = File.Create( fi.Name+ ".zip")) 
              { 
                  using (GZipStream Compress = new GZipStream(outFile, 
                          CompressionMode.Compress)) 
                  { 
                      // Copy the source file into the compression stream. 
                      byte[] buffer = new byte[4096]; 
                      int numRead; 
                      while ((numRead = inFile.Read(buffer, 0, buffer.Length)) != 0) 
                      { 
                          Compress.Write(buffer, 0, numRead); 
                      } 
                      Console.WriteLine("Compressed {0} from {1} to {2} bytes.", 
                          fi.Name, fi.Length.ToString(), outFile.Length.ToString()); 
                  } 
              } 
          } 
      } 
  } 
  </code></pre>
  
  <ol>
  <li><p>If my zip file name is  20110505.zip  after uncompressing i want my file name to be 20110505.txt  . after uncomressing the zip file to text file i want to delete the zip file after compressing</p>
  
  <pre><code>  string Path2 = (string)(Application.StartupPath + "\\TEMP\\" + "\\" + name_atoz);
  
    DirectoryInfo di = new DirectoryInfo(Path2);
    FileInfo fi = new FileInfo(Path2);
    Compress(fi);
  
    public static void Decompress(FileInfo fi) 
    { 
          // Get the stream of the source file. 
          using (FileStream inFile = fi.OpenRead()) 
          { 
              // Get original file extension, for example "doc" from report.doc.gz. 
              string curFile = fi.FullName; 
              string origName = curFile.Remove(curFile.Length - fi.Extension.Length); 
  
              //Create the decompressed file. 
              using (FileStream outFile = File.Create(origName)) 
              { 
                  using (GZipStream Decompress = new GZipStream(inFile, 
                          CompressionMode.Decompress)) 
                  { 
                      //Copy the decompression stream into the output file. 
                      byte[] buffer = new byte[4096]; 
                      int numRead; 
                      while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0) 
                      { 
                          outFile.Write(buffer, 0, numRead); 
                      } 
                      Console.WriteLine("Decompressed: {0}", fi.Name); 
  
                  } 
              } 
          } 
      } 
  </code></pre></li>
  </ol>
  
  <p>I want this because i am creating a project which reads the text file . </p>
  
  <p>Is there any suggestion for my problem.</p>
  
  <p>Thanks In Advance</p>