2

at my job we use this method for an automated job that is trigger when .7zip files are put inside a specific folder:

public void Executer(ref string pChaineContexte, XdCuContexteTravail pContexte)
 {
 var dossierDepot = new XdCuFichier().ObtenirDepot(ref pChaineContexte, pContexte.NomChaine(ref pChaineContexte), "ReceptionSEEL");
 string[] fichiersZip = Directory.GetFiles(dossierDepot);
 foreach (var fichierZip in fichiersZip)
 {
 var fichierVide = string.Concat(dossierDepot, "\\", Path.GetFileNameWithoutExtension(fichierZip));
 Directory.CreateDirectory(fichierVide);
 using (var archive = ArchiveFactory.Open(fichierZip))
 {
 foreach (var entry in archive.Entries)
 {
 if (!entry.IsDirectory)
 entry.WriteToDirectory(fichierVide, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true });
 }
 }
 }
 return;
}

The problem is that I get a lot of the time this error: "File does not have a stream". It does start the decompressing job but there is only one file that is in the new folder and nothing more. After we get the error that I mentionned.

I've read this: Issue partially extracting a 7-Zip archive using SharpCompress and I think this is a real issue.

How do you think I should change my code?

asked Jul 8, 2025 at 21:04
3
  • Side issue - you might be interested in Path.Combine. Commented Jul 9, 2025 at 5:11
  • 1
    Are you sure the file is not used by anything else when you are running your code? If you are using a FileWatcher you probably want to use the NotifyFilters.LastWrite filter. See this question Commented Jul 9, 2025 at 6:42
  • Are you sure the file is complete when you receive the "new file" alert? Perhaps you're opening it while it is still being copied or uploaded, so you have an incomplete file that is not yet a valid ZIP file. Commented Jul 9, 2025 at 14:25

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.