Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 该进程无法访问该文件,因为其他进程正在使用该文件(删除文件夹)_Javascript_C# - Fatal编程技术网

Javascript 该进程无法访问该文件,因为其他进程正在使用该文件(删除文件夹)

Javascript 该进程无法访问该文件,因为其他进程正在使用该文件(删除文件夹),javascript,c#,Javascript,C#,我已将文件写入指定文件夹。在将其写入文件夹后,我将该文件附加到邮件中。将该文件附加到邮件后,我想删除该文件夹。但该文件夹未被删除,并引发异常,原因是“该进程无法访问该文件,因为它正被另一进程使用” 这是我的密码 public HttpResponseMessage SendChannelPartenersMessage(string Name,string FirmName,string Address, string Email,string Mobile)

我已将文件写入指定文件夹。在将其写入文件夹后,我将该文件附加到邮件中。将该文件附加到邮件后,我想删除该文件夹。但该文件夹未被删除,并引发异常,原因是“该进程无法访问该文件,因为它正被另一进程使用”

这是我的密码

     public HttpResponseMessage SendChannelPartenersMessage(string Name,string FirmName,string Address, string Email,string Mobile)                                        
     {
         var httpRequest = HttpContext.Current.Request;
         ContactUs contactUs = new ContactUs();
         contactUs.Address = Address;
         contactUs.Name = Name;
         contactUs.FirmName = FirmName;
         contactUs.Email = Email;
         contactUs.Mobile = Mobile;

         try
         {
             if (httpRequest.Files.Count > 0)
             {
                 contactUs.AttachFileName = WriteAttachedFile(httpRequest, contactUs.Email);

                 if (ContactUsService.SendChannelPartenersMessage(contactUs))
                 {
                     var fileToBeDeleted = contactUs.AttachFileName;
                     var deleteFile = DeleteAttachedFile(contactUs.AttachFileName);
                 }
                 return Request.CreateResponse(HttpStatusCode.OK, contactUs);
             }
             else
             {
                 return Request.CreateResponse(HttpStatusCode.BadRequest);
             }

         }
         catch (Exception e)
         {
             throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
             {
                 Content = new StringContent("An error occurred, please try again or contact the administrator."),
                 ReasonPhrase = "Critical Exception"
             });
         }
   }

    private string WriteAttachedFile(HttpRequest httpRequest, string FileName)
    {         
        var postedFile = httpRequest.Files[0];
        var directoryPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"].ToString() + FileName + "\\\\";
        var filePath = directoryPath + postedFile.FileName;
        Directory.CreateDirectory(directoryPath);
        postedFile.SaveAs(filePath);
        var Path = filePath.Replace("\\", "/");
        return (Path);
    }   

     private bool DeleteAttachedFile(string FileName)     
     {
         if (System.IO.File.Exists(FileName))
         {
             System.IO.File.Delete(FileName);
         }

         string[] words = FileName.Split('/');
         string directoryPath = words[words.Length - 2];

         if (Directory.Exists(directoryPath))
         {
             Directory.Delete(directoryPath);
         }   
         return (true);
    }

这是因为你通过邮件发送的文件仍然没有在接收者端下载。甚至在通过Skype发送文件或复制到U盘时也会发生这种情况。确保在接收者端下载文件

问题是什么?我为写作创建的文件夹未被删除。相反,它引发了一个异常:进程无法访问该文件,因为它正被另一个进程使用。但是用户可能无法下载邮件。如何处置?解决办法是什么?@user3687566我相信收件人不是邮件的收件人。应首先将文件上载到邮件服务器。实际转到您发送邮件的邮件帐户,删除发送的邮件。是。只有在成功发送邮件后,我才会删除文件夹。这是在完成邮寄过程后