web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / How to create and down...
Finance forum

How to create and download txt file by code in D3FO

(0) ShareShare
ReportReport
Posted on by 110

Hi everyone,

I have a task is to create and download a TxT file with a Container parameter. Then, I create TxT file with TextIO but dont know how to download it. Please help me

Thanks,

Best Regards.

Categories:
  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    Hi,

    What do you need this txt file for?

    Best regards

    Ludwig

  • Suggested answer
    Martin Dráb Profile Picture
    241,467 Most Valuable Professional on at

    If you're talking about an interactive session, you can use File::SendFileToUser() or File::SendStringAsFileToUser().

    Note that I have no idea what you mean by "a file with a container parameter" or "download with a container parameter". Please elaborate - and consider whether it's really a requirement or just your idea about implementation details.

  • Nguyen Do Huy Profile Picture
    110 on at

    Hi Ludwig, customer want to download the created text file from D365FO

  • Nguyen Do Huy Profile Picture
    110 on at

    Hi Martin,

    I can create the Txt file usign TextIO class, but i dont know how to download it. File::SendFileToUser() needs a stream as a param but i dont know how to get file stream from my created text file

    Note: I mean create the text file with a container param. Sorry for not being clear.

  • Verified answer
    Martin Dráb Profile Picture
    241,467 Most Valuable Professional on at

    If you want to get a stream, use TextStreamIo instead of TextIo.

  • Nguyen Do Huy Profile Picture
    110 on at

    permission = new FileIoPermission(filename, #io_write);

               permission.assert();

               file = new TextStreamIo();

               if (!file)

                   throw Exception::Error;

               //file.outRecordDelimiter(#delimiterCRLF);

               file.outFieldDelimiter("\n");

               conLength = conLen(con);

               for(i = 1; i<=conLength; i++)

               {

                   line = conPeek(con, i);

                   file.write(line);

               }

               System.IO.FileStream fileStream = file.getStream();

               file::SendFileToUser(fileStream, _filename);

    Here is my code, but when i change to TextStreamIO, the file = new TextStreamIo(); have an error because it's protected. Please help !

  • Verified answer
    Martin Dráb Profile Picture
    241,467 Most Valuable Professional on at

    If you look at methods of TextStreamIo, you'll notice constructForWrite() - that's what you need. It also means that you don't have worry anymore about strange macros such as #io_write.

  • Nguyen Do Huy Profile Picture
    110 on at

    Thanks Martin,

    I changed my constructor to file = TextStreamIo::constructForWrite(); and st works perfectly.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans