You should use a finally block, and close all the Streams there:
finally
{
sourceStream.Close();
requestStream.Close();
response.Close();
}
This way even if you have an exception, everything will be closed.
This happends because maybe you have gotten an exception before the close of that file, and then, when you run your program again, and try to open, is still opened.
Close your file first, and then use the finally block, or the using
statement.
Something like:
using (StreamReader reader = new StreamReader("file.txt"))
{
line = reader.ReadLine();
}
I hope this helps