• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

Mulitple file access

Hi I have a method with the code below to create a file.

if(File.Exists(fileName))
{
      File.Delete(fileName);            
}

byte[] streamBytes = new byte[fileStream.Length];      
fileStream.Read(streamBytes, 0, streamBytes.Length);            
fs.Write(streamBytes, 0, streamBytes.Length);

fs.Close();

But the second time I run the method from the program I get the error

The process cannot access the file "C:\DOCUME~1\xxx\LOCALS~1\Temp\MyFile.xsd" because it is being used by another process.

Anybody know of a workaround
0
auk_ie
Asked:
auk_ie
  • 2
1 Solution
 
brckoslavCommented:
where you have fs = new FileStream() ?
0
 
brckoslavCommented:
and on what line is error raised?
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now