Click here to Skip to main content
14,699,752 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I know this is a common problem but i'm still a newbie to this kind of problem

i used the code below to get all the files in a directory , send it to email and finally delete it i don't know how can i dispose or delete it after using the file, or is there an another way to do this?



string[] filePaths = Directory.GetFiles(filePath, "*.EDI");
                foreach (var item in filePaths)
                {
                    string containerOperator = cmbOperator.SelectedItem.ToString();
                    long containerID = Convert.ToInt64(cmbOperator.SelectedValue);
                    containerOperator = Regex.Replace(containerOperator, "[0-9]", "");
                    containerOperator = Regex.Replace(containerOperator, ",", "");
                    containerOperator = Regex.Replace(containerOperator, @"[^0-9a-zA-Z:,]", "");
                    if (item.Contains(containerOperator))
                    {
                        oCodecoLogic.emailCoarriSenderByVess(containerID, containerOperator, item);
                        File.Delete(item);
                    }
                }


What I have tried:

i tried looping to retry the process but it won't work and i think it's a stupid idea.
Posted
Updated 13-Oct-20 20:01pm

1 solution

You don't.

The reason the file is open is because the email hasn't been transmitted yet or is in the process of being transmitted. You have to wait for that operation to complete before trying to delete the files.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900