Export a Text File in NAV 2013

imclever1205
Member Posts: 94
Hi Guys ,
Does anyone knows the correct code to exectute and Xmlport that needs to write a text file and store it in a location ?
F1 suggested :
But it does not work actually : Microsoft Dynamics NAV
The following error occurred: Could not find a part of the path 'C:\102001.txt'.
I have written a code which uses codeunit File Management and it works fine
This code works fine and export the file on the Client Side in the specified folder but the only issue is that it pops up the Save As Window.
And for my current problem I do not want it to pop up the SaveAs window.I want it to store in the path specified in a background process
Can someone please help or suggest a work around ?
Thank you
Does anyone knows the correct code to exectute and Xmlport that needs to write a text file and store it in a location ?
F1 suggested :
VarXml.CREATE('C:\'+"Sales Shipment Header". "No." + '.txt'); VarXml.CREATEOUTSTREAM(OutputStream); XMLPORT.EXPORT(6059810, OutputStream ); VarXml.CLOSE;
But it does not work actually : Microsoft Dynamics NAV
The following error occurred: Could not find a part of the path 'C:\102001.txt'.
I have written a code which uses codeunit File Management and it works fine
TextFile.CREATE(FilePath); TextFile.CREATEOUTSTREAM(OutStream); OutStream.WRITETEXT(Vendor."Mnemonic Code"+';'+FORMAT(PurchLine.Quantity)+';'+PurchLine."No."+';'+PurchLine.Description+';'+"No."+';'+'Y'); TextFile.CLOSE; FileManagement.DownloadHandler(FilePath,'Test',PurchasePayableSetup."BogPortal Export Path",'(*.txt)|*.txt|All files (*.*)|*.*','');
This code works fine and export the file on the Client Side in the specified folder but the only issue is that it pops up the Save As Window.
And for my current problem I do not want it to pop up the SaveAs window.I want it to store in the path specified in a background process
Can someone please help or suggest a work around ?
Thank you
0
Comments
-
Hi,
Did you try to use "File Management"."DownloadToFile" func.?
Regards,
YukonMake Simple & Easy0 -
Yes i tried this one too and gives the same error and best there are no examples that shows the correct way to do it0
-
Hi,
I've spent some time on mibuso to find a solution for similar case but I couldn't find proper way for "silent" (without Save As window) export data for filtered record.
Based on many tries I built this piece of code. It works for me, so I hope it will be useful.
Fil_ServerFileName := FileMgt.ServerTempFileName('csv');
File2.CREATE(Fil_ServerFileName);
File2.CREATEOUTSTREAM(OutStream);
xmlportname.SETDESTINATION(OutStream);
xmlportname.SETTABLEVIEW(filteredrecord);
xmlportname.EXPORT();
File2.CLOSE();
gFilename := path + filename;
FileMgt.DownloadToFile(Fil_ServerFileName,gFilename);
FILE.ERASE(Fil_ServerFileName);0 -
Hi,
you did not clearly specify whether you need client side file paths or can do it server side. The latter is somewhat easyer and more effective.
But as you say you client side code work save the prompt, I'll give you a code sample for client side storage.
ExpFileName contains the full filename (Drive|Server\share,path,name,extension) of the destination file.TempBlob.Blob.CREATEOUTSTREAM(OutStrm); XMLPORT.EXPORT(XMLPortID,OutStrm); CLEAR(OutStrm); IF TempBlob.Blob.HASVALUE THEN BEGIN BlobFilename := FileMgt.BLOBExport(TempBlob,ExpFilename,FALSE); IF FileMgt.ClientFileExists(BlobFilename) THEN BEGIN FileMgt.MoveAndRenameClientFile( BlobFilename, FileMgt.GetFileName(ExpFilename), FileMgt.GetDirectoryName(ExpFilename); END; END; CLEAR(TempBlob);
Note that FileMgt.BLOBExport, even though you pass it the destination file name, actually only just keeps the extension part an stores it's export to the user's TEMP folder on the client. From there you can the move it to where you wanted it in the first place. NAV's file management is full of obstacles and unexpected behaviour.
I wonder about your (imclever1205) first example. I'd never imagined that would work. On which line does it fail? Either it tries to read from the file you attempt to create or it may fail because of UAC (writing to the root of the system drive requires privileged access) and the error message is bogus.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