Siavash Sajjad
Siavash Sajjad

Reputation: 41

how to delete image file after upload in C#?

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

Answers (2)

ketan italiya
ketan italiya

Reputation: 296

try {
FileInfo TheFile = new FileInfo(MapPath(".") + "\\" + txtFile.Text);
if (TheFile.Exists) {
File.Delete(MapPath(".") + "\\" + txtFile.Text);
}
else {
throw new FileNotFoundException();
}
}

Upvotes: 0

user2674996
user2674996

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

Related Questions