I've shown several examples on this web site of how to get the Notes data directory so it can be used as a temporary place to hold files. There is also a Windows temporary directory that can be used.

Please note... if you have purchased the Reusable Object Library Level 2 application, you can use the "Find New Reusable Objects" feature to quickly download this design element and it's associated documentation at no cost.

First, you have to declare the DLL function that will be used. This goes into the (Declarations) area of your agent or script library:

Then, you just have to call that function in the "right way". That means that you have to obey some API rules when doing the call. I broke my code down into a self-contained function for reuse purposes:

Function GetTempDirectory() As StringDim buffer As StringDim bufferLen As Long

The first API rule we need to observe is that the string memory can't be allocated dynamically by the call. We have to allocate space for the string. 256 characters should be sufficient.

buffer = Space$(256)

The next thing to do is call the function. Note that the return value from the function is the length of the string.

bufferLen = GetTempPath(Len(buffer), buffer)

Since we allocated 256 characters and the path is most likely less than that, our code needs to trim off the extra white space. I make sure that the length returned is "in range" so an error won't happen.

If bufferLen > 0 And bufferLen < 256 Then
buffer = Left$(buffer, bufferLen) End If

Finally, API strings are usually null-terminated (character code 0). The string length returned won't include that, so the block above removed the null terminator. However, if the string length was out of range for some reason, then there still might be a null character in the buffer string. So check for that and keep only the characters to the left of the null character.