string str1 = Path.Combine(Constants.TEMPFOLDER, Guid.NewGuid().ToString()); Directory.CreateDirectory(str1); try { using (MemoryStream memoryStream = new MemoryStream(File.ReadAllBytes(zipFilePath))) { using (ZipInputStream zipStream = new ZipInputStream((Stream) memoryStream)) { ZipEntry nextEntry; while ((nextEntry = zipStream.GetNextEntry()) != null) { string directoryName = Path.GetDirectoryName(nextEntry.Name); string str2 = Path.Combine(str1, directoryName); string fileName = Path.GetFileName(nextEntry.Name); string path = Path.Combine(str2, fileName); if (directoryName.Length > 0) Directory.CreateDirectory(str2); if (fileName != string.Empty) { using (FileStream fileStream = File.Create(path)) formTE.CopyZipEntryToStream(zipStream, (Stream) fileStream); } } zipStream.Close(); } memoryStream.Close(); } } catch (Exception ex) { Thread.Sleep(500); Directory.Delete(str1); throw new Exception("There is an error during unzipping file"); } return str1; 

Constants.TEMPFOLDER - My Documents folder of the current user. The error occurs on the line using (FileStream fileStream = File.Create(path)) , specifically when creating the file. The folder is full access for ALL users. The program does not work under the administrator (it is excluded that there are no rights). Files of xml and txt type are created without problems. An error occurs when creating a file with the extension jpg. There is such a way.

The peculiarity is that the code worked 3 months ago. There is a suspicion that the whole thing in the updates. And this code works on 2 computers out of 3. Windows updates are always installed on the third computer. Tests were conducted on Windows 8.1 (works), Windows 7 SP1 without updates (works), Windows 7 with updates (does not work). Any ideas?

  • Through debugger see which path is transmitted in path - Gennady P
  • @GennadiP The path is passed true, already looked. And the file name does not contain any prohibited characters. - Hazatdum

1 answer 1

Files of xml and txt type are created without problems.

This fact seemed strange to me. It was discovered that the problem was the corporate antivirus Kaspersky. Protection from encryption programs prevented saving images, adding a program exception, or disabling a rule will help.