Reputation: 41
I have a problem on deleting or moving files after upload in ASP.NET.
I am using RadUpload for uploading files and I want to have a remove button for delete the physical file.
However, right after a successful upload I can't delete the physical file and an error will be raised "File in use".
Upvotes: 0
Views: 4938
Reputation: 296
try {
FileInfo TheFile = new FileInfo(MapPath(".") + "\\" + txtFile.Text);
if (TheFile.Exists) {
File.Delete(MapPath(".") + "\\" + txtFile.Text);
}
else {
throw new FileNotFoundException();
}
}
Upvotes: 0
Reputation:
you should delete it your self by writing the code, and I think you should upload it with your code too. Anyway here is a sample code to delete file.
FileInfo info1 = new FileInfo(folderPath + filename);
if (info1.Exists)
{
info1.Delete();
}
Upvotes: 1