GenZiy
GenZiy

Reputation: 1447

StreamWriter generate IOException Unable to find the specified file

I have the following code:

using (StreamWriter writer = new StreamWriter(filename, true))
{
   writer.WriteLine(mydata);
}

that from time to time generate this error: IOException.Message = "Unable to find the specified file".

The filename string is specified by the user and can be a network location like:

\\mycorp\Shared\Data.xml

And mydata variable is a string too.

Is it possible that this code will generate a FileNotFoundException?

Upvotes: 0

Views: 294

Answers (1)

Richardissimo
Richardissimo

Reputation: 5763

The answer to the question "Is it possible that this code will generate a FileNotFoundException?" is: No.

Source: https://msdn.microsoft.com/en-us/library/36b035cb.aspx

I suggest checking where the exception is coming from. It should give a line number in the exception stack trace.

Upvotes: 1

Related Questions