Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have searched google for a solution but it looks like this isn't a common issue so I can't find an answer.

I created a website in asp.net C# with a login system

I have a button that deletes the specified folder on click from my solution(I can't be more clear than this)
This folder contains files that get uploaded by the user but when it is done being used I want the user to have the ability to delete the folder through the website(not needing to go into the solution)

The code I use to do the delete is this

C#
public Boolean deleteFolder(String directory, String FolderName)
    {
        directory = page.Server.MapPath(directory + "/" + FolderName);
        if (Directory.Exists(directory))
        {
            try
            {
                Directory.Delete(directory, true);
            }
            catch (IOException)
            {
                Thread.Sleep(1);
                Directory.Delete(directory, true);
            }
        }
        if (Directory.Exists(directory))
        {
            deleteRecuring(directory);
        }

        return false;
    }

//Deleting the files in the folder first
private void deleteRecuring(String directory)
    {
        try
        {
            string[] files = Directory.GetFiles(directory);
            string[] dirs = Directory.GetDirectories(directory);

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

            foreach (string dir in dirs)
            {
                deleteRecuring(dir);
            }

            Directory.Delete(directory, false);
        } 
        catch {}                
        if (File.Exists(directory))
        {
            Thread.Sleep(1);
            //deleteRecuring(directory);
        }
    }


The issue I have is that when I click to delete the folder and all of its contents it logs the user(who ever is logged into the website) out of the website.

I am unsure why this is happening and hoping someone could look at my code and maybe guide me to the answer and how to fix it

If this is by any means unclear, please tell me what else I am missing so I can add it in.
Posted
Comments
JoCodes 12-Dec-13 4:33am    
Where the application folder resides?
Member 10395722 12-Dec-13 4:34am    
On a server
JoCodes 12-Dec-13 4:38am    
I meant the path like whether inside the virtual directory folders or somewhere else?
JoCodes 12-Dec-13 4:45am    
a solution added . please check and revert.

1 solution

The reason is ASP.NET engine recycles the AppDomain when a modification is done under the application folder and its monitored. A suggestion will be to use App_Data for the same.

Or else make the monitoring ignored by having a workaround as below link

http://dotnetslackers.com/Community/blogs/haissam/archive/2008/11/12/disable-session-expiration-when-using-directory-delete.aspx[^]

Try and revert.

Hope this helps you...
 
Share this answer
 

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