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 :
Small and medium business | Business Central, N...
Answered

Text File creation

(0) ShareShare
ReportReport
Posted on by 106

We have a requirement where we need to create a text file in BC Cloud.

Using stream functions for the same.

The separator in this file is not a tab.

This file has a defined length for each value and if something is not satisfying is less in length then it remains blank and if more than length then it truncates.

How to achieve this in code.

Example:

Sales Line info with Item no and name and amount .two lines I will explain

ITEM0001fruit    200.76

ITEM0001basket200.76

so 

outstrea.write(no+description)+tab+outstream.write(amount);

here TAB will shift the amount to right but here this is not the case

so first place value is fixed to 20:

so if 16 is the length of both(no+description) those 16 places should be occupied by value and the rest will remain blank and if satisfies length like in line 2 or more then it gets truncated to 20only. so no shift in the amount place holder.

No change in amount position ,it will start at 21 position only as an example

so how to achieve this if length keeps on varying how to add those many of spaces to keep length fixed.

Sample like

20 dot places

....................amount

value exist

ITEM01fruit........amount

so all 20 Is occupied then only other value starts

I have the same question (0)
  • Verified answer
    Saurabh Shah Profile Picture
    4,560 on at

    Hello, 

    In BC cloud, you can't use Write function. you need to use WriteText to create text file. for fixed spacing, you can use PADSTR. below is an example. 

    You may need to use Codeunit "Temp Blob" as variable
    I am also declaring one Text variable for Item number + Description as "ItemDesc"
    TempBlob.Createoutstream(outstrea);
    ItemDesc := Format(Salesline.No) + Format(Salesline.Description)
    outstrea.WriteText(Padstr(ITemDesc,16,' ') // here the last ' ' which is defined as space can be replaced with any other character like '.' 
    outstrea.WriteText(Format(Amount));
    Above code just for the example purpose only to understand Padstr function. 
    Regards,
    Saurabh

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,577

#2
YUN ZHU Profile Picture

YUN ZHU 888 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 778 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans