Thursday, February 6, 2014

Code to create file in folder in Axapta

You can create file in folder using below code in Axapta. Just type code in job and run that job then you can check test.txt file get created in temp folder of c drive.


In WinAPIServer class you can check code in bus layer in WS_FileCreate method.

 Com         oFileSystem;  
   COMVariant     varFile;  
   InteropPermission  perm;  
   boolean       b;  
   varFile   = new COMVariant(COMVariantInOut::OUT, COMVariantType::VT_BSTR);  
   perm = new InteropPermission(InteropKind::ComInterop);  
   if (perm == null)  
     return null;  
   oFileSystem = new COM('Scripting.FileSystemObject');  
   return oFileSystem.CreateTextFile(varFile);