【问题标题】:How I Delete File after uploading in ASP.net FileUpload Control在 ASP.net FileUpload Control 中上传后如何删除文件
【发布时间】:2014-02-01 06:20:26
【问题描述】:
string savePath = Server.MapPath("\\Upload_File\\");
// Get the name of the file to upload.
string fileName = email_attach.FileName;
string pathToCheck = savePath + fileName;


email_attach.SaveAs(pathToCheck);

string file = pathToCheck;
Attachment data = new Attachment(file);
mail.Attachments.Add(data);

SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
email_attach.Dispose();
FileInfo file_Delete = new FileInfo(pathToCheck);
if (file_Delete.Exists)
{
    file_Delete.GetAccessControl();
    file_Delete.Delete();
}

当我这样做时,它会抛出异常

在 mscorlib.dll 中发生了“System.IO.IOException”类型的异常,但未在用户代码中处理

附加信息:该进程无法访问文件“C:\Users\User\Documents\Visual Studio 2013\WebSites\Email_Sent_Web\Upload_File\DMP.edx”,因为它正被另一个进程使用。

我如何解决请帮助,谢谢提前

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    尝试在mail.Attachments.Add(data);下方写data.Dispose();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-02
      • 2013-11-01
      • 2018-10-24
      • 2012-06-20
      • 2011-03-08
      • 1970-01-01
      相关资源
      最近更新 更多