0

I am uploading a file but before that, I am checking end deleting files in the upload directories. The issue is that the upload occurs faster than the deletion of files.

 public IActionResult Upload(FixedNgaExisting model, IFormFile file)
        {
            

            //check if files exist in upload directory
            //empty the folder if it's not empty
            DirectoryInfo dir = new DirectoryInfo(path);
            if (!System.IO.File.Exists(path))
            {
                foreach (FileInfo fFile in dir.GetFiles())
                {
                    fFile.Delete();
                }
            }

            
            
                using (ZipArchive archive = ZipFile.OpenRead(fileName))
                {
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        if (entry.FullName.EndsWith(".dbf", StringComparison.OrdinalIgnoreCase))
                        {
                            string destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.Name));

                            //extraxt the ".dbf" file to directory
                            if (destinationPath.StartsWith(extractPath, StringComparison.Ordinal))
                                entry.ExtractToFile(destinationPath);

                        }
                    }
                }
        }

How should I delay the upload? Or how should I execute the deletion first and then proceed to the upload?

0 Answers0