Axapta : The WINAPI class on Axapta

Axapta : The WINAPI class on Axapta
Like most AX developers I use the WINAPI class quite often. Its a very useful class when handling files that need to be accessed outside of the AX environment

  static void FO_WinApi(Args _args)
      str     root        = "C:";
      str     path        = "C:\\dionne";
      str     fileName    = "SalesInvoice.pdf";
      str     fileName2   = "SalesInvoice1.pdf";
      str     file        = path + "\\" + fileName;
      str     file2       = path + "\\" + fileName2;
      int     x, y;
      // Does folder exist?
      print WinAPI::folderExists(path);
      // Does file exist?
      print WinAPI::fileExists(file);
      // Copy file.
      print WinAPI::copyFile(file,file2);
      // New file exists?
      print WinAPI::fileExists(file2);
      // Delete new file.
      print WinAPI::deleteFile(file2);
      // New file still there?
      print WinAPI::fileExists(file2);
      // Get current cursor position.
      [x, y] = WinAPI::getCursorPos();
      print x;
      print y;
      // Get time and date format.
      print WinAPI::getSystemLocaleDateStr();
      print WinAPI::getSystemLocaleTimeStr();
      // Gets current computer name.
      print WinAPI::getComputerName();
      // Gets total disk space.
      print int2str(WinAPI::getDiskTotalSpaceInKb(root)
             / 1000) + " MB";
      // Gets current free space on disk.
      print int2str(WinAPI::getDiskFreeSpaceInKb(root)
             / 1000) + " MB";
      // Date when file was last accessed.
      print WinAPI::getFileAccessedDate(file);
      // Time when file was last accessed(In seconds).
      print WinAPI::getFileAccessedTime(file);
      // Gets path to temp directory.
      print WinAPI::getTempPath();
      // Gets a generated temporary filename, prefix "FO_".
      print WinAPI::getTempFilename(path, "FO_");
In addition to file information the WINAPI class can execute different file types from within Dynamics AX by of course using the file name as a parameter.

For example lets say you want to launch a PDF file saved in table within AX. WinAPI::ShellExecute() will do this for you.

No comments:

Post a Comment