-2

I already protect the csv files with zip by using the ionic.zip.dll

see the below code

using (ZipFile zip = new ZipFile())
{
   TargetFileName = TargetNamePrefix;
   OutPutDirectoryPath = TargetLocation + "\\" + TargetNamePrefix + ".zip";                  

   zip.Password = zipFilePassword;
   zip.AddFiles(FilePaths, TargetNamePrefix);
   zip.Save(OutPutDirectoryPath)
}

here file paths is string[] variable it consists of files(csv/text) Names. TargetNamePrefix means inside zipfile folder Name.OutPutDirectoryPath means output directoty with zipfileName. then How can i Open the those protected files in write mode why because I want to write Datainto the Protected csv file.

SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
Pavan
  • 11
  • 2
  • possible duplicate of [Decompressing password-protected ZIP files with .NET 4.5](http://stackoverflow.com/questions/13160490/decompressing-password-protected-zip-files-with-net-4-5) – BCdotWEB Mar 13 '15 at 12:29

1 Answers1

0

You can just extract them using a similar method:

using(ZipFile zip = ZipFile.Read(OutPutDirectoryPath))
{
   zip.Password = zipFilePassword; 
   try 
   {
      zip.ExtractAll(TargetLocation);
   }
   catch (BadPasswordException e) 
   {
      // handle error
   }
}  

Update Access single file entry into a stream without extracting

string entry_name = TargetNamePrefix + ".csv"; // update this if needed
using (ZipFile zip = ZipFile.Read(OutPutDirectoryPath))
{
   // Set password for file
   zip.Password = zipFilePassword; 

   // Extract entry into a memory stream
   ZipEntry e = zip[entry_name];
   using(MemoryStream m = new MemoryStream())
   {
      e.Extract(m);
      // Update m stream
   }

   // Remove old entry
   zip.RemoveEntry(entry_name);

   // Add new entry
   zip.AddEntry(entry_name, m);

   // Save
   zip.Save(OutPutDirectoryPath);
}
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
  • Sorry ... I am not interested in Extraction, because I want to protect the data from the outside world, just I need to open The required file from the ZIP file in write mode Please help me to Crack this .... – Pavan Mar 16 '15 at 05:15
  • @Pavan - See updates, let me know if that works for you. – SwDevMan81 Mar 16 '15 at 12:29
  • Actually I need to open the csv/txt file available in Password protected zip file I have to write data into that files by using the SreamWriter Class Can you please Help Me to solve this.. – Pavan Mar 18 '15 at 12:53
  • Can i Open The Password Zip file by using the StreamWriter Class – Pavan Mar 18 '15 at 12:55
  • In The above code You r removing the Existing file and adding Same new file but i need to write a data in to exiting file only.Can you please help me to Solve This... – Pavan Mar 20 '15 at 09:45