发送邮件后如何删除生成的pdf [英] how to delete the generated pdf after sending the mail

查看:179
本文介绍了发送邮件后如何删除生成的pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用一种形式发送邮件..im在邮件中附加pdf并发送邮件..当我发送邮件pdf文件时,将在特定位置生成..例如-

Im using one form in my application to send the mail..im attaching a pdf in the mail and sending the mail..when i send the the mail pdf file will be generated in a particular location..for example--

D:\ABC Report 06202012 42554 PM.pdf

...当我一直发送邮件报告时..如何在发送邮件后使用C#编码删除pdf ..当我使用file.move,file.replace或file.delete时显示错误

...when i send the mail report has been generated all the time..how to delete that pdf using C# coding after sending the mail..when i use file.move,file.replace or file.delete it is showing an error

The process cannot access the file because it is being used by another process.



请提供一些解决方案.



please provide me some solutions

推荐答案

我们可以看到负责通过电子邮件发送PDF文件的代码吗?您的问题可能是由于未释放的内存流引起的.如果您使用的是附件类,则应执行以下操作:

Can we see a code that is responsible for sending a PDF file via e-mail? Your problem might be caused by not released memory stream. If you''re using an Attachment class then you should do like the following:

using (Attachment data = new Attachment("document.pdf",  MediaTypeNames.Application.Octet))
{
    // 1. Adding attachment to the e-mail message
    // 2. Sending out the e-mail message
}



调用Send方法之后,请调用Dispose处理您的邮件对象:



After calling the Send method make a call to Dispose of your mail message object:

objSMTPClient.Send(objMailMsg); 
objMailMsg.Dispose(); 


在.net 3.5中

In .net 3.5

using (Process proc = new Process())
               {
                   proc.StartInfo.UseShellExecute = false;
                   proc.StartInfo.CreateNoWindow = true;
                   proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                   proc.StartInfo.FileName = "ABC.EXE";
                   proc.StartInfo.Arguments = "Report 06202012 42554 PM.pdf";
                   proc.StartInfo.RedirectStandardError = false;
                   proc.StartInfo.RedirectStandardOutput = false;
                   proc.StartInfo.UseShellExecute = false;
                   proc.StartInfo.CreateNoWindow = true;
                   proc.Start();
                   proc.WaitForExit();
               }



proc.WaitForExit() ;这是关键


在CMD中:



proc.WaitForExit(); This is the key


In CMD:

Use the "Start /wait <command>". <command> = D:\ABC Report 06202012 42554 PM.pdf


这篇关于发送邮件后如何删除生成的pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆