Thursday, March 22, 2012

The file exist but cant delete on server (c#)

Hi all, have an c# page that allows users to uploaded files to the server. I was hoping to also hoping to allow users to delete files aswell. I have the following code, but it dose no delete the file, even though it can find the file (the response.write outputs). Here is my code:

if(File.Exists(sPhysicalPath + @dotnet.itags.org."\" + sOrgFileName)){
Response.Write("delete");
File.Delete(sPhysicalPath + @dotnet.itags.org."" + sOrgFileName);
}

Any suggestions appreciated.

Thanks,

Hi,

by default, and for security reasons, ASP.NET doesn't have the privileges to perform IO actions like deleting a file. You can create a new windows user account that has the same privileges as the ASP.NET account and augment it with the needed privileges to delete certain files on the disk. After that you can impersonate your application with that new account by setting, in the web.config of your application, the<identity impersonate="true" userName="yournewaccount" />

Grz, Kris.

0 comments:

Post a Comment