Friday, May 14, 2010

How to retrieve the location of various Ax and Windows folders

Axapta

For retrieving Ax client folder information, we can use the xInfo class, with the directory method.
Here are some examples.


The bin directory of the Ax client
xInfo::directory(DirectoryType::Bin);

Result:
C:\DynamicsAx\Ax2009\Server\Standard32bit\Client\Bin\


The Axapta client temporary folder
xInfo::directory(DirectoryType::Temp)
Result:
C:\DynamicsAx\Ax2009\Server\Standard32bit\Client\appl\standard\tmp\


The include folder of the share directory
xInfo::directory(DirectoryType::Include);

Result:
C:\DynamicsAx\Ax2009\Server\Standard32bit\Client\share\include\


A different one, the application log directory

xInfo::AOTLogDirectory();
Result:
C:\Users\Public\Microsoft\Dynamics Ax\Log\


Windows

But there is more. Sometimes, you might have a need for a temporary file. Your Windows client can help you with this.
How to get the location of the Windows temporary folder (a personal, user specific folder, located in your profile)

WinApi::getTempPath()

Or if you like shortcuts: System.IO.Path::GetTempPath()

Outcome:

C:\Users\administrator.HQ\AppData\Local\Temp\7\

And you can get a temporary file name as well, so no need to create a routine that generates a random id:

WinApi::getTempFilename(WinApi::getTempPath(),'Ax')
(you only need to supply the folder name, and some prefix)
This will give you something like this

C:\Users\administrator.HQ\AppData\Local\Temp\7\Ax1518.tmp

Not enough folder information for you? No problem. You can retrieve all your Windows folder information with the WinApi::getFolderPath method. All you need to do is to supply the right parameter, coming from the WinAPI macro.

What about the temporary folder of Internet Explorer:

#WinAPI

WinAPI::getFolderPath(#CSIDL_INTERNET_CACHE);

The desktop of the current user:

#WinAPI

WinAPI::getFolderPath(CSIDL_DESKTOPDIRECTORY);


Other macro names you can use as a parameter: CSIDL_FAVORITES (favorites), CSIDL_WINDOWS (Windows directory, alternative for WinApi::getWindowsDirectory()), CSIDL_FONTS (fonts directory of Windows), ...

3 comments:

  1. Feel free to visit this dynamics blog

    http://daynamicsaxaptatutorials.blogspot.com

    ReplyDelete
  2. One important thing to note is that it depends on what tier these methods are called on. So if you call on server vs. client, it'll return a different path.

    ReplyDelete