Sunday, January 17, 2021

Copy file from one place to another in D365 F&O

Code to copy file from one place to another


        Set    permissionSet;

        FileName fileName            = "C:\\Import\\FROM SMART VISTA\\a.txt";

        FileName fileNameMoved = "C:\\Import\\MOVED INTO AX\\a.txt";


        permissionSet = new Set(Types::Class);

        permissionSet.add(new InteropPermission(InteropKind::ClrInterop));

        permissionSet.add(new FileIOPermission(fileName , 'RWD'));

        permissionSet.add(new FileRepository());

        CodeAccessPermission::assertMultiple(permissionSet);

        WinAPIServer::copyFile(fileName,fileNameMoved,true);

        CodeAccessPermission::revertAssert();