This project is read-only.
1
Vote

Close stream once rar extraction is done

description

Hello,
      I am using NUnrar extraction and first I am saving rar to temp folder and I am checking valid extension in rar file. If is there any mismatch found then break that operation and delete the rar from temporary folder.
I am not able to delete the rar it is giving "file is is used by another process" issue.

Please suggest how to close stream?

Below is my code:

RarArchive archive = RarArchive.Open(filetoread);
                foreach (RarArchiveEntry entry in archive.Entries)
                {

                    ext = Path.GetExtension(entry.FilePath);
                    var fileext = (from e in db.upload_extensions where e.extention_itself == ext select e).SingleOrDefault();
                    if (fileext == null)
                    {
                        filename = Path.GetFileName(entry.FilePath);
                        result = false;
                        break;
                    }
                    else
                    {
                        result = true;
                    }

                }
if (result != true)
            {
                File.Delete(filetoread);

            }
            else
            {
//write next code
}

comments