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:
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Downloading Files Business Central Online

    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/.../

  • JesusP Profile Picture
    5 on at
    RE: Downloading Files Business Central Online

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

  • Martinho Costa Profile Picture
    779 on at
    RE: Downloading Files Business Central Online

    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?

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Downloading Files Business Central Online

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

  • Martinho Costa Profile Picture
    779 on at
    RE: Downloading Files Business Central Online

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

  • Martinho Costa Profile Picture
    779 on at
    RE: Downloading Files Business Central Online

    direction = Export;

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

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Downloading Files Business Central Online

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

  • Martinho Costa Profile Picture
    779 on at
    RE: Downloading Files Business Central Online

    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.
  • Verified answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Downloading Files Business Central Online

    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;

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,277 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,019 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans