c# - File.Create() can't be executed because file is still used by another process -



c# - File.Create() can't be executed because file is still used by another process -

i seek create file after checking if directory exists, , if file exists.

but when programme gets line error can't create file because it's beingness used process. weird thing shouldn't. when file doesn't exist.

file.create(directory.getcurrentdirectory() + "\\channels\\" + savefile).close()

the error occurs in part of code, grab not included. know should have used using() should work too. don't fancy redo part way untill works way.

if (!system.io.directory.exists(system.io.directory.getcurrentdirectory() + "\\channels")) { connection.logger.log("making " + system.io.directory.getcurrentdirectory() + "\\channels", false, logmode.info); system.io.directory.createdirectory(system.io.directory.getcurrentdirectory() + "\\channels"); } string savefile = program.removeforbiddenfilecharacters(this.channelname + ".channel"); string savefilepath = system.io.directory.getcurrentdirectory() + "\\channels\\" + savefile; filestream filestream = null; streamwriter streamwriter = null; seek { if (file.exists(directory.getcurrentdirectory() + "\\channels\\" + savefile)) { file.delete(directory.getcurrentdirectory() + "\\channels\\" + savefile); } file.create(directory.getcurrentdirectory() + "\\channels\\" + savefile).close(); streamwriter = new streamwriter(system.io.directory.getcurrentdirectory() + "\\channels\\" + savefile); //safe stuff file streamwriter.close(); } grab (exception e)

if you've deleted file, os might prevent creating within few seconds because it's not done deleting yet.

why don't open file writing, instead of deleting , recreating it?

c# .net system.io.file

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -