1
The problem appears in the penultimate line of the code below, what can I do? NOTE: I have already tried to use "Using" in the Streamreader, but it has not solved.
string CJ;
string CJ1;
string CJ2;
StreamReader LJ = new StreamReader(Application.StartupPath + @"\Jo\" + cbJ.Text + ".ij");
{
CJ = LJ.ReadLine();
LJ.Close();
}
StreamReader L1 = new StreamReader(Application.StartupPath + @"\Ja\" + cbJ1.Text + ".jad");
{
CJ1 = LJ1.ReadLine();
LJ1.Close();
}
foreach (string newPath in Directory.GetFiles(CJ, "*", SearchOption.AllDirectories))
{
File.Copy(newPath, newPath.Replace(CJ, CJ1 + "/" + cbJ.Text), true);
}
StreamReader L2 = new StreamReader(Application.StartupPath + @"\Ja\" + cbJ2.Text + ".jad");
{
CJ2 = LJ2.ReadLine();
LJ2.Close();
}
foreach (string newPath in Directory.GetFiles(CJ, "*", SearchOption.AllDirectories))
{
File.Copy(newPath, newPath.Replace(CJ2 + "/" + cbJ.Text, CJ), true);
}
Put some clearer names on the variables that help locate the problem. You create L1, but close LJ1, create L2, but close LJ2, hard to track code like this.
– Bacco
In fact the code could be much simpler than that, which would avoid this error.
– Maniero
If you have a new question, ask a new question, do not change the answer in a way that completely changes the question. You had a problem and it was solved. If you have not solved everything, you can ask new questions.
– Maniero
Do the following Carlos, post this new code as a new question, since we passed this stage, and explain in the new how the directory is and how it is to stay after the function, that we try to help. Try to give more details, not only the code, and with examples of how you would like the directory before and after.
– Bacco