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

error while moving file from one folder to other

(0) ShareShare
ReportReport
Posted on by 238

Microsoft Dynamics NAV
---------------------------

A call to System.__ComObject.MoveFile failed with this message: Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED)
---------------------------
OK
---------------------------

code:

CREATE(FSO,FALSE,TRUE);
FSO.MoveFile('D:\INTERFACE FILES\UAT\CLIENTS\PRIMARY\'+RecErrorLog."File Name"+'.txt','D:\INTERFACE FILES\UAT\CLIENTS\ERROR\');

Name         DataType                   Subtype 
FSO            Automation '              Windows Script Host Object Model'.FileSystemObject

i am not able to move when it use in one codeunit1but with other codeunit2 it works do't know why?

codeunit 1

IF NOT codeunit50010.RUN THEN
//MESSAGE('The last error was: ' + GETLASTERRORTEXT);
BEGIN
RecErrorLog.INIT;
RecErrorLog."No.":= Srno;
RecErrorLog."Error Message":= GETLASTERRORTEXT;
//RecErrorLog."Source Type" :=
RecErrorLog.Date := TODAY;
RecErrorLog.Time :=TIME;
RecErrorLog."File Name":=codeunit50010.GetErrorFileName;
RecErrorLog.INSERT;

CREATE(FSO,FALSE,TRUE);
FSO.MoveFile('D:\INTERFACE FILES\UAT\CLIENTS\PRIMARY\'+RecErrorLog."File Name"+'.txt','D:\INTERFACE FILES\UAT\CLIENTS\ERROR\');//Not Working
Srno :=Srno+1;
MESSAGE('Runner codeunit Run Successfully');
END;

codeunit 2

XmlportCMU50003.SetSourceType(SourceTypeGlobal);
XmlportCMU50003.GetFileName(Filepath);
FileName:=XmlportCMU50003.GetInterfaceFileName;
SetErrorFileName(ErrorFileName);
CREATE(FSO,FALSE,TRUE);
FSO.MoveFile('D:\INTERFACE FILES\UAT\CLIENTS\PRIMARY\'+GetErrorFileName+'.txt','D:\INTERFACE FILES\UAT\CLIENTS\ERROR\');//working

//MESSAGE(FORMAT(GetErrorFileName));
varXmlFile.OPEN(Filepath);
varXmlFile.CREATEINSTREAM(varInputStream);
XMLPORT.IMPORT(XMLPORT::"Client Invoice - Header", varInputStream);

I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    on at
    RE: error while moving file from one folder to other

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks.

  • Suggested answer
    Suresh Kulla Profile Picture
    50,235 Super User 2025 Season 2 on at
    RE: error while moving file from one folder to other

    There is a known issue of using MoveFile related to permissions, please refer KB310316. I would use the copy function and then delete the source file.

  • DineshM Profile Picture
    238 on at
    RE: error while moving file from one folder to other

    Hi Suresh sir , I have used copy function as follows but giving error on erasing  the file

    codeunit 1 main

    //++++++++50000 Client Master Upload SB

    XmlportCMU50000.SetSourceType(SourceTypeGlobal);

    XmlportCMU50000.GetFileName(Filepath);

    FileName:=XmlportCMU50000.GetInterfaceFileName;

    SetErrorFileName(FileName);

    varXmlFile.OPEN(Filepath);

    varXmlFile.CREATEINSTREAM(varInputStream);  

    XmlportCMU50000.SETSOURCE(varInputStream);

    XmlportCMU50000.IMPORT;

    varXmlFile.CLOSE;

    SetMoveFileName(FileName,1);

    //-------

    SetErrorFileName(ErrorFile : Text)

    ErrorFileName:=FileName;

    GetErrorFileName() : Text

    EXIT(ErrorFileName);

    GetMoveFileName(VAR SuccessFile : ARRAY [6] OF Text)

    COPYARRAY(SuccessFile,CollectmoveFileName,1);

    SetMoveFileName(ColleectArryname : Text;i : Integer)

    CollectmoveFileName[i] := ColleectArryname;

    GetOpenFile(VAR FileVar : File)

    FileVar := varXmlFile;

    LOCAL GetFile(VAR VarFile : File)

    VarFile := varXmlFile;

    codeunit 2

    IF NOT codeunit50010.RUN THEN  

     BEGIN

    //=======================moving error to error log table if unsuccessful import

       RecErrorLog.INIT;  

       RecErrorLog."No.":= Srno;

       RecErrorLog."Error Message":= GETLASTERRORTEXT;

       //RecErrorLog."Source Type" :=

       RecErrorLog.Date := TODAY;

       RecErrorLog.Time :=TIME;

       RecErrorLog."File Name":=codeunit50010.GetErrorFileName;

       RecErrorLog.INSERT;

       //=======================moving file to error Folder if unsuccessful import

       IF RecErrorLog."File Name" <> '' THEN BEGIN

       FILE.COPY('D:\INTERFACE FILES\UAT\CLIENTS\PRIMARY\'+RecErrorLog."File Name"+'.txt','D:\INTERFACE FILES\UAT\CLIENTS\ERROR\'+RecErrorLog."File Name"+'.txt');

       FileName := 'D:\INTERFACE FILES\UAT\CLIENTS\PRIMARY\'+RecErrorLog."File Name"+'.txt';

       IF EXISTS(FileName) THEN

       IF FileVar.OPEN(FileName) THEN

        FileVar.CLOSE;

       // codeunit50010.GetOpenFile(FileVar);

       // FileVar.CLOSE;

       FILE.ERASE('D:\INTERFACE FILES\UAT\CLIENTS\PRIMARY\'+RecErrorLog."File Name"+'.txt');///////////////// I/O exception

       END;

       Srno :=Srno+1;

         MESSAGE('Runner codeunit Run Successfully');

     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

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 > Small and medium business | Business Central, NAV, RMS

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,808

#2
Sumit Singh Profile Picture

Sumit Singh 2,554

#3
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,140

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans