Why is access to the path denied?

前端 未结 29 1507
刺人心
刺人心 2020-11-22 15:25

I am having a problem where I am trying to delete my file but I get an exception.

if (result == \"Success\")
{
     if (FileUpload.HasFile)
     {
         t         


        
29条回答
  •  日久生厌
    2020-11-22 15:57

    I had this error thrown when I tried to rename a folder very rapidly after it had been either moved or created.

    A simple System.Threading.Thread.Sleep(500); solved it:

    void RenameFile(string from, string to)
    {
       try
       {   
          System.IO.File.Move(from, to)      
       }   
       catch 
       {  
           System.Threading.Thread.Sleep(500);      
           RenameFile(from, to);      
       }   
    }
    

提交回复
热议问题