web
You’re offline. This is a read only version of the page.
close
Skip to main content
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,594 on at
    RE: Saving file to specifies path in xml

    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
    RE: Saving file to specifies path in xml

    Hi,

    You can also use Filename property in XMLPort

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


    Hope it helps

  • Community Member Profile Picture
    on at
    RE: Saving file to specifies path in xml

    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
    RE: Saving file to specifies path in xml

    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
    RE: Saving file to specifies path in xml

    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
    RE: Saving file to specifies path in xml

    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
    RE: Saving file to specifies path in xml

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

  • Community Member Profile Picture
    on at
    RE: Saving file to specifies path in xml

    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
    RE: Saving file to specifies path in xml

    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
    RE: Saving file to specifies path in xml

    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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Saurav.Dhyani Profile Picture

Saurav.Dhyani 2 Super User 2025 Season 2

#2
RK-25090803-0 Profile Picture

RK-25090803-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans