R
rn5a
How do I find out whether a file is currently being used by some
process or not (including the ASP.NET process)?
A Web Form has a ListBox which lists all the directories & files
existing in a directory on the server. There are 2 Buttons as well -
'btnCreateFile' for creating a new file & 'btnRenameFile' for renaming
a file.
I am creating a new file by first checking whether the file name
entered by the user already exists or not. If not, then using
File.Create, the new file gets created else the user is shown a message
saying that the file already exists. Similarly for renaming files, I am
first checking whether the new file name the user has entered already
exists or not. If not, then using File.Move the file gets renamed.
I click 'btnCreateFile' which pops-up a JavaScript 'prompt' dialog. I
enter a file named, say, 'MyFile.txt' (without the quotes) & the new
file gets created. What I find is if I try to rename this newly created
file immediately after it gets created by clicking 'btnRename' (this
also pops-up a JavaScript 'prompt' dialog), then the following error
gets generated:
The process cannot access the file because it is being used by another
process.
which points to the File.Move line which renames the file.
How do I overcome this error?
I know that the FileStream class supports asynchronous file access but
how do I rename a file (& also a directory) using the FileStream class?
process or not (including the ASP.NET process)?
A Web Form has a ListBox which lists all the directories & files
existing in a directory on the server. There are 2 Buttons as well -
'btnCreateFile' for creating a new file & 'btnRenameFile' for renaming
a file.
I am creating a new file by first checking whether the file name
entered by the user already exists or not. If not, then using
File.Create, the new file gets created else the user is shown a message
saying that the file already exists. Similarly for renaming files, I am
first checking whether the new file name the user has entered already
exists or not. If not, then using File.Move the file gets renamed.
I click 'btnCreateFile' which pops-up a JavaScript 'prompt' dialog. I
enter a file named, say, 'MyFile.txt' (without the quotes) & the new
file gets created. What I find is if I try to rename this newly created
file immediately after it gets created by clicking 'btnRename' (this
also pops-up a JavaScript 'prompt' dialog), then the following error
gets generated:
The process cannot access the file because it is being used by another
process.
which points to the File.Move line which renames the file.
How do I overcome this error?
I know that the FileStream class supports asynchronous file access but
how do I rename a file (& also a directory) using the FileStream class?