Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

error while moving file from one folder to other

Posted on by 221

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);

  • DineshM Profile Picture
    DineshM 221 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

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 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.

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels 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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans