Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I made a service which deletes any folder mentioned in the path. my web service is published on my IIS server.

I have another web page which referring this web service by calling a method in it with the folder path.

I am getting an error as

Quote:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.IO.IOException: Access to the path 'E:\ws4test\foldertodelete\New Folder' is denied.
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive)



my web method is as follows:

C#
[WebMethod(Description = "automatically delete the folder mentioned in the path")]
    public string deletefoldermethod(string folderpath)
    {
        DirectoryInfo targetfolder = new DirectoryInfo(folderpath);
        string[] files = Directory.GetFiles(folderpath);
        string[] dirs = Directory.GetDirectories(folderpath);

        foreach (string file in files)
        {
            File.SetAttributes(file, FileAttributes.Normal);
            File.Delete(file);
        }

        foreach (string dir in dirs) 
        {
            Directory.Delete(dir,true);
        }
        string msg = "Folder is successfully deleted";
        return msg;
    }



and the web page code to call this is..
localhost.deletefolder obj = new localhost.deletefolder();
       string path = @"E:\ws4test\foldertodelete\";
       string msg = obj.deletefoldermethod(path);
       lblmsg.Text = msg;


Am I missing something???
Posted
Updated 18-Jan-12 2:17am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900