Can't create txt file in client

catiamatos1991
Member Posts: 158
HI everyone, I'm trying to create a txt file (nav 2016) with some data and for that I tried the "Hello World" example
So in the page action I added a button called TXT with the following code:
MESSAGE('WORD');
MyFile.CREATE( 'C:\teste.txt');
MyFile.CREATEOUTSTREAM(MyOutStream);
MyOutStream.WRITETEXT('Hello World!');
MyFile.CLOSE; // To end the writing and write out to the file.
MESSAGE('END WORD');
I read that nav stores the file in NAV server instead of client. How to download or save the file in the client ? I read about soem codeunits but I'm using Nav 2016 can i use that code? Below there's a example..
https://docs.microsoft.com/en-us/dynamics-nav/walkthrough--transferring-a-file-from-microsoft-dynamics-nav-server-to-the-client
how to use this in my context? Or are any other solutions ?
So in the page action I added a button called TXT with the following code:
MESSAGE('WORD');
MyFile.CREATE( 'C:\teste.txt');
MyFile.CREATEOUTSTREAM(MyOutStream);
MyOutStream.WRITETEXT('Hello World!');
MyFile.CLOSE; // To end the writing and write out to the file.
MESSAGE('END WORD');
I read that nav stores the file in NAV server instead of client. How to download or save the file in the client ? I read about soem codeunits but I'm using Nav 2016 can i use that code? Below there's a example..
https://docs.microsoft.com/en-us/dynamics-nav/walkthrough--transferring-a-file-from-microsoft-dynamics-nav-server-to-the-client
how to use this in my context? Or are any other solutions ?
0
Best Answer
-
Serverfilename Var Text
Archivo Var File
StreamOut Var OutStream
ClientFilePath Var Text
FileManagement Var CU419
ServerFileName:=FileManagement.ServerTempFileName('txt');
ClientFilePath:='C:\asdf.txt';
Archivo.CREATE(ServerFileName);
Archivo.CREATEOUTSTREAM(StreamOut);
StreamOut.WRITETEXT("Sales Shipment Line"."Document No.");
Archivo.CLOSE;
FileManagement.DownloadToFile(ServerFileName,ClientFilePath);
Giving thanks is always wellcome5
Answers
-
You can use the codeunit 419 (File Management), inside you have this function
DownloadToFile(ServerFileName : Text;ClientFileName : Text)
0 -
Serverfilename Var Text
Archivo Var File
StreamOut Var OutStream
ClientFilePath Var Text
FileManagement Var CU419
ServerFileName:=FileManagement.ServerTempFileName('txt');
ClientFilePath:='C:\asdf.txt';
Archivo.CREATE(ServerFileName);
Archivo.CREATEOUTSTREAM(StreamOut);
StreamOut.WRITETEXT("Sales Shipment Line"."Document No.");
Archivo.CLOSE;
FileManagement.DownloadToFile(ServerFileName,ClientFilePath);
Giving thanks is always wellcome5 -
I'm getting this error,
0 -
Can u activate the debugger in order to see where the problem is?Giving thanks is always wellcome0
-
I got the error "System.IO.File.copy" failed because I don't have access to write in "C:\teste.txt", so I create a new folder and write to "C:\teste\teste.txt" and I could download the file1
-
The access to a root folder on any drive is restricted by default. You need Admin permissions on the system to create files in C:\ - that's why you cannot store anyting directly in C:\ folder.
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_Guzek0
-
[Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!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