Error: Write to file failed

Aravindh_Navision
Member Posts: 258
Hi friends,
[Version: NAV 2009 SP1 Classic client]
I am extracting data from NAV to text file through the automation from report using 'Microsoft ActiveX Data Objects 2.8 Library'.Stream'. When a file with same name already exists in the folder, I am getting below error:
This message is for C/AL programmers.
The call to member SaveToFile failed.ADODB.Stream returned the following message:
Write to file failed.
Can anyone please let me know how to overcome this issue?
Thanks and Regards.
[Version: NAV 2009 SP1 Classic client]
I am extracting data from NAV to text file through the automation from report using 'Microsoft ActiveX Data Objects 2.8 Library'.Stream'. When a file with same name already exists in the folder, I am getting below error:
This message is for C/AL programmers.
The call to member SaveToFile failed.ADODB.Stream returned the following message:
Write to file failed.
Can anyone please let me know how to overcome this issue?
Thanks and Regards.
0
Comments
-
Hi,
It may caused by several possible reason, one is the file path is not correct.0 -
Thank you allenyyzhou. Any solution..? Do I need to change in coding or in security of the folder?0
-
Could you paste all source code related in here?0
-
Hi allenyyzhou, heres is the code.
Global variables
Name DataType Subtype
adostream Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Stream
CRL Char
LFL Char<Declared and assigned variables and concatenated as shown below> CRL := 13; LFL := 10; CREATE(adostream); adostream.Open; adostream.Charset('UTF-8'); concRowID01 := RowID01 + '|' + Serie01 + '|' + Folio01 + '|' + PostingDateTime01 + '|' + WaytoPay01 + '|' + PaymentTerms01 + '|' + txtSubtotal01 + '|' + txtDiscount01 + '|' + CurrCode01 + '|' + txtExchRate01 +'|' + txtTotal01 + '|' + txtTotalWithholdingTax01 + '|' + txtTotalTransferredTax01 + '|' + TypeOfReceipt01 + '|' + PmtMethod01 + '|' + EmissionPlace01 + '|' + AmountInWords01 + '|' + Confirmation01 + '|' + UseCFDI01 +'|' + Relation01; [b]adostream.WriteText(concRowID01 + FORMAT(CRL) + FORMAT(LFL));[/b] concRowID03 := RowID03 + '|' + RFC03 + '|' + CompanyName03 + '|' + FiscalRegime03 + '|' + Branch03 + '|' + Country03 + '|' + Street03 + '|' + OutDoorNo03 + '|' + InteriorNo03 + '|' + SuburbName03 + '|' + StateCity03 + '|' + DelegacionMunicipo03 + '|' + ZipCode03; [b]adostream.WriteText(concRowID03 + FORMAT(CRL) + FORMAT(LFL));[/b] concRowID04 := RowID04 + '|' + CustomerNo04 + '|' + RFC04 + '|' + CustomerName04 + '|' + FiscalAddress04 + '|' + TaxID04 + '|' + Country04 + '|' + Street04 + '|' + OutDoorNo04 + '|' + InteriorNo04 + '|' + SuburbName04 + '|' + StateCity04 + '|' + DelegacionMunicipo04 + '|' + ZipCode04 + '|' + Email04; [b]adostream.WriteText(concRowID04 + FORMAT(CRL) + FORMAT(LFL));[/b] concRowID05 := RowID05 + '|' + ProSerCode05 + '|' + IDNo05 + '|' + txtQty05 + '|' + IDUnit05 + '|' + UOM05 +'|' + Desc05 + '|' + txtUnitPrice05 + '|' + txtLineAmount05 + '|' + txtLineDiscount05; [b]adostream.WriteText(concRowID05 + FORMAT(CRL) + FORMAT(LFL));[/b] concRowID05A := RowID05A + '|' + txtBase05A + '|' + Tax05A + '|' + FactorType05A + '|' + txtTaxRate05A + '|' + txtAmount05A; [b]adostream.WriteText(concRowID05A + FORMAT(CRL) + FORMAT(LFL));[/b] concRowID07 := RowID07 + '|' + TaxDescription07 + '|' + FactorType07 + '|' +txtTaxRate07 + '|' + txtAmount07; [b]adostream.WriteText(concRowID07 + FORMAT(CRL) + FORMAT(LFL));[/b] SISTring := COPYSTR("Sales Invoice Header"."No.",1,3); IF SISTring = 'INT' THEN BEGIN MESSAGE('Internal Invoices cannot be extracted to text file for Electronic Invoicing. ' + 'Check whether you have filtered any internal invoices starting with INT.'); CurrReport.QUIT; END ELSE adostream.SaveToFile('D:\TestFile\UTF8\' + FORMAT(WORKDATE,0,'Invoice_' + "No." + '_<Day,2>' + '<Month,2>' + '<Year4>') + '.txt'); adostream.Close;
Please let me know, if you need any more details.
Thanks.0 -
How about
OutFile := 'D:\TestFile\UTF8\Invoice_' + "No." + '_'+FORMAT(WORKDATE,0,'<Day,2><Month,2><Year4>') + '.txt'; adostream.SaveToFile(OutFile, 2);
ADO Stream SaveToFile Method :SaveToFile FileName, SaveOptions
A SaveOptionsEnum value that specifies whether a new file should be created by SaveToFile, if it does not already exist. Default value is adSaveCreateNotExists. With these options you can specify that an error occurs if the specified file does not exist. You can also specify that SaveToFile overwrites the current contents of an existing file.Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Thanks Slawek, It worked..0
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