Reputation: 2772
So I have some code that allows a user to import certain excel spreadsheets into the DB. Now, I save a copy of the file to the server so I can read it:
fupMYfile.SaveAs(System.IO.Path.Combine(target, fupMYfile.FileName));
So all works well there till i try to delete the file when I am done with it. I don't receive and error, and I have checked the code gets called, however, it will not delete the file and won't give an error.
System.IO.File.Delete(target + fupMYfile.FileName);
I did try making sure that IIS_IUSRS has full access to the folder, so I know that is not an issue.
Anybody have any ideas?
thanks
Upvotes: 0
Views: 1763
Reputation: 1
File.Delete
doesn't give any exception and hence will not throw an error, and we need to give full absolute path
File.Delete("C:\temp\tmpFile.txt");
and not
File.Delete("tmpFile.txt");
Upvotes: 0
Reputation: 700382
You are not using the same file name. You are saving it something like c:\somefolder\somefile.xls
, then you try to delete it at c:\somefoldersomefile.xls
.
Use Path.Compbine
to put the folder namd and the file name together:
System.IO.File.Delete(System.IO.Path.Combine(target, fupMYfile.FileName));
Upvotes: 7