Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

NAV 2013 R2 - XML Port, How to close the file that the XML Port uses for importing

(0) ShareShare
ReportReport
Posted on by

Dear Developers,

I'm writing in order to ask for some help with File management in 2013 r2 xml port.

The "problem" is, that after importing the records from the file, I'd have to move it from the folder path it was opened from, to another folder (based on whether the import was successfull (in this case it has to be moved to an "Archived" folder), or it finished with errors (in which case it has to be moved to a "Failed" folder). The thing is, that in 2009 i could simply use the "currFile.CLOSE" command to close the file and then move it, but with 2013, this commandline was (re)moved somehow, and I just can't seem to work my way around it.

However, I found a codeunit called File Management (419), in which there IS a function for closing a file, but as a reference it expects a 'File' type variable, which i can not seem to pass from the XMLPort via. currXMLPort.FILENAME (Type Conversion error occurs).

I'm pretty desperate now, so if any of you might have any ideas or hints as to how this problem could be solved, please feel free to share your mind with me (or us, if there are any other developers who are concerned as well regarding this matter :) )

Regards : Ruben 

*This post is locked for comments

  • keoma Profile Picture
    32,727 on at
    RE: NAV 2013 R2 - XML Port, How to close the file that the XML Port uses for importing

    my pleasure. if my answer also satisfied your question, please verify.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: NAV 2013 R2 - XML Port, How to close the file that the XML Port uses for importing

    Hello Jonathan, Thank you for your quick response.

    We managed to solve it by making a temporary copy of the file, process it and depending on the outcome, we moved the original file to the desired location.

    Again, thank you for replying! Regards:

    Ruben H.

  • Verified answer
    keoma Profile Picture
    32,727 on at
    RE: NAV 2013 R2 - XML Port, How to close the file that the XML Port uses for importing

    try following sample code:

    // the variables

    Name DataType Subtype Length

    SalesOrderXmlFile Text

    XmlStream InStream

    IsImported Boolean

    ImportXmlFile File

    FileMgmt Codeunit File Management

    // the code

    SalesOrderXmlFile := 'C:\Temp\SalesOrder.xml';

    ImportXmlFile.OPEN(SalesOrderXmlFile);

    ImportXmlFile.CREATEINSTREAM(XmlStream);

    IsImported := XMLPORT.IMPORT(XMLPORT::"Sales Header", XmlStream);

    IF (IsImported = TRUE) THEN

     MESSAGE('The import from XML is complete.')

    ELSE

     MESSAGE(GETLASTERRORTEXT);

    ImportXmlFile.CLOSE;

    FileMgmt.MoveClientFile(SalesOrderXmlFile,'c:\temp\archive\salesorder.xml');

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics NAV (Archived)

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans