Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii ,

I am trying to create a directory and the later I try to flush that directory .. but at the time of deleteing it gives me access denied error for that path .. Please suggest ..

C#
if (Directory.Exists(deletePath))
                        {
                            Directory.Delete(ClearDirectory, true);
                            Directory.Delete(deletePath, true);
                        }

                        #endregion

                        if (!Directory.Exists(Server.MapPath(pdfExportPath)))
                        {
                            Directory.CreateDirectory(Server.MapPath(pdfExportPath));
                        }
Posted
Comments
George Jonsson 20-Nov-14 8:21am    
What does this line do?
Directory.Delete(ClearDirectory, true);

1 solution

Try the code below and see if you get the same error.

C#
string path = Server.MapPath(pdfExportPath);
if (!Directory.Exists(path))
{
    Directory.CreateDirectory(path);
}

using (File.Create(Path.Combine(path, "Test.txt")));

if (Directory.Exists(path))
{
    Directory.Delete(path, true);
}

Can you delete a directory manually on that server?
If not, check the access rights for the account you are using.

It is also a bit confusing as you used different paths in the different code segments.
Is this intentional or a mistake?
 
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