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 :
Microsoft Dynamics NAV (Archived)

Saving file to specifies path in xml

(0) ShareShare
ReportReport
Posted on by

Hey guys.
I have created an xml ports to export data from T18 and T222. but i need to save the  file in the path specified in general ledger setup . Any suggestions pleaseeee !

Thank you in advance!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    I Gusti Made Ari Profile Picture
    3,600 on at

    You need to run it from codeunit . Below is the sample code :

    GLSetup.GET;
    
    XmlFile.CREATE(GLSetup."File Path and Name");
    XmlFile.CREATEOUTSTREAM(OutStreamVar);
    XMLPORT.EXPORT(XMLPORT::"Your XmlPort",OutStreamVar); 
    XmlFile.CLOSE;


  • Suggested answer
    Guillem Padilla Profile Picture
    427 on at

    Hi,

    You can also use Filename property in XMLPort

    currXMLport.FILENAME := GLSetup."File path";


    Hope it helps

  • Community Member Profile Picture
    on at

    hey guys.First thank you for replying.
    I get an error of type: An I/O exception ocurred.

  • Suggested answer
    Guillem Padilla Profile Picture
    427 on at

    Maybe it is because you are trying to do something with the file while it is opened.

    If you set FILENAME property, you do not need to use streams...

    Can you share your code?

  • Community Member Profile Picture
    on at

    IF GeneralLedgSetup.GET() THEN

     PathFile := GeneralLedgSetup."Route of Export (DPV)";

    DestinationFile := FileMng.ServerTempFileName('csv');

    Filevar.CREATE(DestinationFile);

    Filevar.CREATEOUTSTREAM(OutstreamVar);

    OutstreamVar.WRITETEXT('No.' + ';');

    OutstreamVar.WRITETEXT('Name' + ';');

    OutstreamVar.WRITETEXT('Address' + ';');

    OutstreamVar.WRITETEXT('City' + ';');

    OutstreamVar.WRITETEXT('Postal Code' + ';');

    OutstreamVar.WRITETEXT('County' + ';');

    OutstreamVar.WRITETEXT('Code of ship to' + ';');

    OutstreamVar.WRITETEXT('Name' + ';');

    OutstreamVar.WRITETEXT('Address' + ';');

    OutstreamVar.WRITETEXT('City' + ';');

    OutstreamVar.WRITETEXT('Postal Code' + ';');

    OutstreamVar.WRITETEXT('County' + ';');

    Cust.RESET;

    ShipToAddress.RESET;

    Cust.SETRANGE("Second Level Field", 'MASS MARKET');

    Cust.SETRANGE("Blocked Field", Cust."Blocked Field"::" ");

    IF Cust.FINDSET THEN REPEAT

     ShipToAddress.SETRANGE("Customer No.", Cust."No.");

     ShipToAddress.SETRANGE("Blocked Field",FALSE);

     IF ShipToAddress.FINDSET THEN BEGIN

    OutstreamVar.WRITETEXT(ShipToAddress.Code + ';');

    OutstreamVar.WRITETEXT(ShipToAddress.Name + ';');

    OutstreamVar.WRITETEXT(ShipToAddress.Address + ';');

    OutstreamVar.WRITETEXT(ShipToAddress.City + ';');

    OutstreamVar.WRITETEXT(ShipToAddress."Post Code" + ';');

    OutstreamVar.WRITETEXT(ShipToAddress.County + ';');

    END;

    OutstreamVar.WRITETEXT(Cust."No."+ ';');

    OutstreamVar.WRITETEXT(Cust.Name + ';');

    OutstreamVar.WRITETEXT(Cust.Address + ';');

    OutstreamVar.WRITETEXT(Cust.City + ';');

    OutstreamVar.WRITETEXT(Cust."Post Code" + ';');

    OutstreamVar.WRITETEXT(Cust.County + ';');

    UNTIL Cust.NEXT = 0;

    FileMng.DownloadToFile(DestinationFile, PathFile);

    Filevar.CLOSE;

  • Community Member Profile Picture
    on at

    Sorry i forget to tell that i remade it in codeunit because i didnt know how to make xml export csv to the path i have specified in GLsetup.

  • Verified answer
    Guillem Padilla Profile Picture
    427 on at

    You should close the file before download it, just switch the two last lines

  • Community Member Profile Picture
    on at

    Thank you so much !!!!!It worked.Some little problems with the delimiter because data is shown all in a row but ill try to fix it .Thanks A lotttt :)

  • Verified answer
    Guillem Padilla Profile Picture
    427 on at

    You are welcome!

    You can fix it  using 2 variables (Char)

    CR := 13;

    LF := 10;

    Adding this at the end of each row

    OutstreamVar.WRITETEXT(FORMAT(CR)+FORMAT(LF));

  • Community Member Profile Picture
    on at

    Thanks  a lot :)

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 > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans