全部好, i我使用SMTP发送电子邮件,并通过文件上传控件将附件添加到电子邮件中,并通过邮件发送附件,但是对于第一个时间,如果我通过电子邮件发送文件邮件正确,但发送邮件后,如果我通过文件上传控件添加相同的文件,我会得到错误 该进程无法访问文件'D:\Program Files \Express\Temp \ SupportAttachments\ support.txt',因为它正被另一个进程使用。 我将文件从上传控件上传到网格,从网格中挑选文件并附加到邮件中。 /> 这是我的代码:
HI ALL, i am sending the email using SMTP and adding the attachements to the email from file upload control and sending the attachements with mail,but for the first time if i am sending the file through email the mail is going correctly but after sending the mail, for the secoind time if i am adding the same file through file upload control i am getting theerror "The process cannot access the file 'D:\Program Files\Express\Temp\SupportAttachments\support.txt' because it is being used by another process. " I am uploading the files from upload control to grid an dfrom grid picking the files and attaching to the mail.. here is my code:
foreach (GridViewRow gvrow in grdfiledetails.Rows) { Label lbl = (Label)gvrow.FindControl("lblfilename"); string SupportAttachmentFilePath = "D:\\Program Files\\Duck Creek Technologies\\Express\\Temp\\SupportAttachments"; SupportAttachmentFilePath += "\\" + lbl.Text; string BasePathValue = lbl.Text; firstAttachment = new Attachment(SupportAttachmentFilePath); firstAttachment = new Attachment(SupportAttachmentFilePath, MediaTypeNames.Application.Octet); mail.Attachments.Add(firstAttachment); //attach1 = BasePathValue; //firstAttachment.Dispose(); } try { SmtpServer.Send(mail);}<pre lang="c#">请帮助该怎么做
Please help what to do
推荐答案以前的流程尚未完成,这就是错误, 结束这个过程需要时间 r发送电子邮件后你就可以从代码中结束这个过程了。 它可以帮助你... Previous process has not been yet completed, thats y it is getting error, it takes time to end the process r else after sending email you end the process from code. it may helps you...
变量 firstAttachment 在foreach循环之外声明 - 改变它,在里面声明它。接下来,仅创建一次附件;还要确保没有重复项(两个文件名相同的附件)! The variable firstAttachment is declared outside the foreach loop - change that, declare it inside. Next, create the attachment only once; also make sure there are no duplicates (two attachments with the same filename)!
更多推荐
使用C#发送邮件时出现问题
发布评论