Writing files to "My Documents"

Discussions specific to Team Developer 5.1.

Writing files to "My Documents"

Postby andy.anderson » Thu Jul 08, 2010 9:23 am

Hello,

Is there a reliable way to write/read files in a user's "My Documents", or similar system directory across multiple windows OS? Any direction would be much appreciated.

Thanks,
Andy Anderson
HAB, Inc.
andy.anderson
 
Posts: 7
Joined: Tue May 04, 2010 12:27 pm

Re: Writing files to "My Documents"

Postby Christof » Thu Jul 08, 2010 11:47 pm

Try SHGetSpecialFolderPath from shell32.dll.

With Constant:
Code: Select all
Number: CSIDL_MYDOCUMENTS = 0x000C


External Function Declaration:
Code: Select all
Library name: Shell32.dll
   ThreadSafe: No
   Function: SHGetSpecialFolderPathA
      Description: Retrieves the path of a special folder, identified by its CSIDL.
            (see MSDN for more)
      Export Ordinal: 0
      Returns
         Boolean: BOOL
      Parameters
         Window Handle: HWND
         Receive String: LPSTR
         Number: INT
         Boolean: BOOL


you can call something like this:
Code: Select all
Call SalStrSetBufferLength( l_sFolder, 500 )
If SHGetSpecialFolderPathA( hWndNULL, l_sFolder, CSIDL_MYDOCUMENTS, TRUE )
   ! ...


This is from TD42 Code. You propably have to convert this to unicode version with proper string handling.

hth,
Christof
Christof
 
Posts: 200
Joined: Tue Dec 02, 2008 3:58 pm
Location: Frankfurt/Germany

Re: Writing files to "My Documents"

Postby andy.anderson » Fri Jul 09, 2010 8:36 am

Thank you very much Christof. Works beautifully. I am using FOLDERID_Desktop = 0x0000 and CSIDL_DESKTOP = 0x0000 (Desktop instead of My Documents) as constants to accomodate Windows 7 and earlier OS versions, but it works great.

Cheers,
Andy
andy.anderson
 
Posts: 7
Joined: Tue May 04, 2010 12:27 pm


Return to Team Developer 5.1

Who is online

Users browsing this forum: No registered users and 1 guest