deleting files

  • Thread starter Thread starter troy
  • Start date Start date
T

troy

Hello,

I have the following code that run in the page_load section:

private void Page_Load(object sender, System.EventArgs e)
{
/// Create uploads folder in the Virtua; directory if one doesnt exist
AppPath = Request.PhysicalApplicationPath + UploadDirectory;
if(!Directory.Exists(AppPath))
Directory.CreateDirectory(Request.PhysicalApplicationPath +
UploadDirectory + "\\");
if(File.Exists(AppPath+"\\uploaded.txt"))
File.Delete(AppPath+"\\uploaded.txt");
}

The File.Delete command throws an except if the uploaded.txt file exists in
the application path\uploads folder - i guess because it has no permissions
on on it. How do I over come this?

thanks
 
Hello,

File.Delete can throw 8 different exceptions. I think that we need to know
which one, so we do not have to guess what the problem is.

You are probably getting:

System.UnauthorizedAccessException

MSDN tells me that this happens for this:

The caller does not have the required permission.
-or-

path is a directory.

-or-

path specified a read-only file.


Is anything of this true? Can you please take a look at the file you are
trying to delete, and make sure that the account you are running ASP.NET
under has permissions to delete the file?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top