.NET: IOException for permissions when creating new file?

Posted by Rosarch on Stack Overflow See other posts from Stack Overflow or by Rosarch
Published on 2010-03-25T14:53:43Z Indexed on 2010/03/25 15:03 UTC
Read the original article Hit count: 476

Filed under:
|
|
|

I am trying to create a new file and write XML to it:

FileStream output = File.Create(Path.Combine(PATH_TO_DATA_DIR, fileName));

The argument evaluates to:

C:\path\to\Data\test.xml

The exception is:

The process cannot access the file 'C:\path\to\Data\test.xml' because it is being used by another process.

What am I doing wrong here?

UPDATE: This code throws the same exception:

StreamWriter writer = new StreamWriter(Path.Combine(PATH_TO_DATA_DIR, fileName));

UPDATE 2: The file I am trying to create does not exist in the file system. So how can be it in use?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET