How to delete file from file directory after sending email?

Chowdary
Member Posts: 148
Hi NAVFamily!
I'm using Bullzip to create invoice PDF and storing in file directory (ex: c:\temp) and sending mails using CU 400. So, all invoices going to "c:\temp"
here is the code:
Is there a way to delete file from "c:\temp" after sending email using C/AL code instead of storing?
Thanks
Regards
Chowdary
I'm using Bullzip to create invoice PDF and storing in file directory (ex: c:\temp) and sending mails using CU 400. So, all invoices going to "c:\temp"
here is the code:
IF ISCLEAR(BullZipPDF) THEN
CREATE(BullZipPDF);
ReportID := REPORT::"Sales Invoice";
FileDirectory := 'C:\temp';
Window.OPEN('Processing Customer ######################1##');
Object.GET(Object.Type::Report,'',ReportID);
Window.UPDATE(1,"No.");
PDFFileName := "No." + '.pdf';
BullZipPDF.Init;
BullZipPDF.LoadSettings;
RunOnceFile := BullZipPDF.GetSettingsFileName(TRUE);
BullZipPDF.SetValue('Output',FileDirectory+PDFFileName);
BullZipPDF.SetValue('Showsettings', 'never');
BullZipPDF.SetValue('ShowPDF', 'no');
BullZipPDF.SetValue('ShowProgress', 'no');
BullZipPDF.SetValue('ShowProgressFinished', 'no');
BullZipPDF.SetValue('SuppressErrors', 'yes');
BullZipPDF.SetValue('ConfirmOverwrite', 'no');
BullZipPDF.WriteSettings(TRUE);
Customer2 := "SMTP Customer";
Customer2.SETRECFILTER;
REPORT.RUNMODAL(ReportID,FALSE,FALSE,Customer2);
TimeOut := 0;
WHILE EXISTS(RunOnceFile) AND (TimeOut < 10) DO BEGIN
SLEEP(1000);
TimeOut := TimeOut + 1;
END;
Window.CLOSE;
CLEAR(SMAIL);
SMAIL.CreateMessage(Name,EMail,EMail,"No."+'SubSMTP',"No."+'BSMTP',FALSE);
SMAIL.AddAttachment(FileDirectory+"No."+'.pdf');
SMAIL.Send;
Is there a way to delete file from "c:\temp" after sending email using C/AL code instead of storing?
Thanks
Regards
Chowdary
Pleasure in the job puts perfection in the work
0
Answers
-
Did you try with
ERASE(FileName)0 -
Hi Mohana,
I'm getting this error message
you cannot use the file C:\temp\1000.pdf because it is already in use.
code usedCLEAR(SMAIL);
SMAIL.CreateMessage(Name,EMail,EMail,"No."+'SubSMTP',"No."+'BSMTP',FALSE);
SMAIL.AddAttachment(FileDirectory+"No."+'.pdf');
SMAIL.Send;
ERASE(FileDirectory+"No."+'.pdf');
code usedCLEAR(SMAIL);
SMAIL.CreateMessage(Name,EMail,EMail,"No."+'SubSMTP',"No."+'BSMTP',FALSE);
SMAIL.AddAttachment(FileDirectory+"No."+'.pdf');
SMAIL.Send;
TimeOut1 := 0;
WHILE EXISTS(FileDirectory+"No."+'.pdf') AND (TimeOut < 10) DO BEGIN
SLEEP(1000);
TimeOut1 := TimeOut1 + 1;
END;
ERASE(FileDirectory+"No."+'.pdf');
this code is taking long time and not responding
am I doing wrong?
please correct me
Thanks
Regards
ChowdaryPleasure in the job puts perfection in the work0 -
sorry!!
correction to the code
WHILE EXISTS(FileDirectory+"No."+'.pdf') AND (TimeOut1 < 10) DO BEGIN
it's TimeOut1, not TimeOut
corrected codeCLEAR(SMAIL);
SMAIL.CreateMessage(Name,EMail,EMail,"No."+'SubSMTP',"No."+'BSMTP',FALSE);
SMAIL.AddAttachment(FileDirectory+"No."+'.pdf');
SMAIL.Send;
TimeOut1 := 0;
WHILE EXISTS(FileDirectory+"No."+'.pdf') AND (TimeOut1 < 10) DO BEGIN
SLEEP(10000);
TimeOut1 := TimeOut1 + 1;
END;
ERASE(FileDirectory+"No."+'.pdf');
with this code, it's giving the same error, i.e.,
you cannot use the file C:\temp\1000.pdf because it is already in use.
depending on the sleep it's taking time to give error message
Thanks
Regards
ChowdaryPleasure in the job puts perfection in the work0 -
This is a known issue with older version of codeunit 400 SMTP Mail, SMTP automation. You can find the updated automation here on my blog: http://gotcal.com/index.php/2010/08/att ... eunit-400/
Remember to change the code in codeunit 400 to include the port no, and also call the Dispose after the SEnd function.0 -
SNielsen wrote:This is a known issue with older version of codeunit 400 SMTP Mail, SMTP automation. You can find the updated automation here on my blog: http://gotcal.com/index.php/2010/08/att ... eunit-400/
Remember to change the code in codeunit 400 to include the port no, and also call the Dispose after the SEnd function.
could you add a .txt of that cu400? when will microsoft release an update?
the hotfix shows this, thx.0 -
SNielsen wrote:This is a known issue with older version of codeunit 400 SMTP Mail, SMTP automation. You can find the updated automation here on my blog: http://gotcal.com/index.php/2010/08/att ... eunit-400/
Remember to change the code in codeunit 400 to include the port no, and also call the Dispose after the SEnd function.Did you try with
ERASE(FileName)Pleasure in the job puts perfection in the work0 -
Pleasure in the job puts perfection in the work0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions