File creation problem

  • Thread starter Thread starter Patrick De Ridder
  • Start date Start date
P

Patrick De Ridder

I have a coding problem, modelled by the trial code below
I don't understand the error, however elementary this is.
Pleases assist,
Patrick.

try
{
FileStream stream1 = new
FileStream(@"c:\trial\trial.006",FileMode.OpenOrCreate,FileAccess.Read) ;
stream1.Close();
}
catch
{
Directory.CreateDirectory(@"c:\trial");

/////////////////////// I get an error in the next
line//////////////////////////

FileStream stream = new
FileStream(@"c:\trial\trial.006",FileMode.Create,FileAccess.Write) ;
stream.Close();
}
 
Patrick,

What is the problem you are coming across? Is an exception thrown? If
so, what is the exception? Also, in your code, you should be catching a
specific exception, not just all exceptions. The exception thrown might be
one that indicates that something other than the directory existing is the
problem.

Hope this helps.
 
Patrick,

What is the problem you are coming across?

Components of the path cannot be found. That is ther error being
indicated by the debug option.

Which I don't understand because the first part has been created by
the line above and the second part is being created by the line
proper. So I am totally at a loss here.
 
The problem has been solved. Many thanks. The learning experience was
to check the availability of the directories at the highest level in
the system structure, which in my case is the main form that calls
child forms as required.
 
Back
Top