Calling a DeleteDirectory Method from a Web Service

E

Eric Levin

I am trying to call a DirectoryInfo.Delete function from a Web Service but
am getting an Access Denied Error:
System.UnauthorizedAccessException: Access to Path "..." is Denied.

I have tried using Impersonation and setting the FileIOPermissionAttributes,
but am still getting the same error:

Thanks,

[WebMethod]
//[FileIOPermissionAttribute(SecurityAction.PermitOnly, Write =
"F:\\DirectoryName")]
public bool DeleteDirectory(string Directory)
{
//ImpersonateUser("UserName", "Password", "MACHINE/DOMAIN");
string FTPPath = @"f:\DirectoryName\" + Directory;
FileIOPermission f; // = new FileIOPermission(PermissionState.None);
f = new FileIOPermission(FileIOPermissionAccess.AllAccess, FTPPath);
DirectoryInfo ftp = new DirectoryInfo(FTPPath);
ftp.Delete(true);
ftp.Refresh();
//StopImpersonateUser();
if (ftp.Exists == true)
return false;
else
return true;
}

Eric Levin
Sounddogs.com
 

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

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,206
Latest member
SybilSchil

Latest Threads

Top