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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Business Central forum

Downloading Files Business Central Online

(0) ShareShare
ReportReport
Posted on by 779

Before, to create a file in the server and download it to the client we just had to something such as:

File.Create(ServerFile)

File.CREATEOUTSTREAM(ServerFile)

DOWNLOAD (...)

Now in Business Central Online those functions are not supported. I'm aware to download I have the DownloadFromStream Function. But I dont know how to create server file first.

Any idea?

Categories:
I have the same question (0)
  • Verified answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Here an example:

    procedure CreateTxtFile(FileName: Text)
    var
        InStr: InStream;
        OutStr: OutStream;
        tmpBlob: Record TempBlob temporary;
    begin    
        tmpBlob.Blob.CreateOutStream(OutStr);        
        OutStr.WriteText('Your Text');      
        tmpBlob.Blob.CreateInStream(InStr);
        DownloadFromStream(InStr, '', '', '', FileName); 
    end;
  • Martinho Costa Profile Picture
    779 on at

    Thanks for the reply Stefano. I'm using the logic you mentioned, but since I'm exporting the xmlport data I have something similiar to this:

                            tmpBlob.Blob.CreateOutStream(OutputStream);
    
                            XMLfile.SETDESTINATION(OutputStream);
                            XmlFile.Export;
    
                            tmpBlob.Blob.CreateInStream(Inputstream);
                            DownloadFromStream(Inputstream, '', '', '', FileName);
    I'm able to export the structure with its tags but is not loading the data.
    It could be a problem from the filters/code responsible to fill the table but it's not since with the old code was working well.
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    Is the XMLport definition correct? Is export enabled in the XMLport?

  • Martinho Costa Profile Picture
    779 on at

    direction = Export;

    Guess that's what you mean. Also tried to export in CSV but still just exporting the columm titles.

  • Martinho Costa Profile Picture
    779 on at

    Stefano.. If I have multiple WriteText... how can I add a line break between them? Tried \\ but not working.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    By simply using OutStr.WriteText() you have a new line inserted (carriage return).    

  • Martinho Costa Profile Picture
    779 on at

    Hello Stefano,

    Since DownloadFromStream will always download to a default transfer folder and the ToFolder parameter is not supported on WebClient. Is there another way set the file to be saved in a different destination folder?

  • JesusP Profile Picture
    5 on at

    Thanks Stefano, but is it possible to download the file in a specific directory for the web version? Or what can be an alternative?

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    This is not directly possible on SaaS because the SaaS environment cannot see your local folders. You can save a file to Azure Blob storage and then download from here to your local drive.

    I’ve described the solution on the “Mastering Dynamics 365 Business Central” book. 
    Here you can see how to do that (forget only the sFTP part):

    demiliani.com/.../

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 > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans