c# - IOException was unhandled -
this question has answer here:
i'm working files on c#, cose supposed delete lines file mentioned here:
var tmpfile = path.gettempfilename(); var linestokeep = file.readlines(path).where(l => l.startswith("removeme")==false); file.writealllines(tmpfile, linestokeep); file.delete(path); file.move(tmpfile,path);
but i'm getting exception: ioexception unhandled
when running code saying:
the process can not access file because being used process
in instruction: file.delete(path);
how can check process using file, or there reason problem?
use fileshare enumeration instruct os allow other processes (or other parts of own process) access same file concurrently.
using (var stream = file.open(path, filemode.open, fileaccess.write, fileshare.read)) { }
Comments
Post a Comment