gpt4 book ai didi

c# - 发送后删除附件

转载 作者:太空宇宙 更新时间:2023-11-03 20:21:35 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
delete attachment file


我试图在使用以下代码发送文件后自动删除文件:

        protected void btnSend_Click(object sender, EventArgs e)
{
// Inserting attachment to the email
using (Attachment data = new Attachment("C:\\local\\vCardGenerator.Website\\" + "FirstName_LastName.vcf", MediaTypeNames.Application.Octet))
{

// add Send E-mail class
SendvCard smtp = new SendvCard();

// Calls method to class
smtp.MailvCard("anonymous@domain.com", "C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" + ".vcf");
}

// Status label + Delete file
lblStatus.Text = "vCard Send to:" + " " + txtMail.Text;


//Delete file after being send as an attachment with the mail
FileInfo DeleteFileInfo = new FileInfo("C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" + ".vcf");
if (DeleteFileInfo.Exists)
File.Delete("C:\\local\\vCardGenerator.Website" + "\\" + "FirstName_LastName" + ".vcf");

没有“自动删除”的调试运行非常顺利,它甚至发送带有附件的电子邮件,但是当我在发送后尝试删除附件时,我收到以下错误弹出窗口:

The process cannot access the file. (~\"Path") because it is being used by another process.

有没有人知道为什么会出现这个错误?
我需要先处理文件吗?

如果需要,愿意提供任何其他/更多信息。

提前致谢,

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com