DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: short cut for path to My Documents in XP

  1. #1
    Join Date
    Oct 2004
    Posts
    102

    Question short cut for path to My Documents in XP

    I've been told that there's some kind of abreviated way to indicate the XP path to My Documents. Something possibly with the "%". I'd appreciate details if such a shortcut exists.

    Thanks

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750
    Try the following:

    Environ("USERPROFILE") & "\My Documents"
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  3. #3
    Join Date
    Aug 2005
    Posts
    85
    Due to the dynamic nature of Windows with its ability to allow users to put their My Documents folder almost anywhere, Paul's suggestion to use the Environ function will only work if the user has not changed anything. The code below will return the folder no matter where it is!

    Code:
    Option Explicit
    
    Private Declare Function lstrlenW Lib "kernel32" _
        (ByVal lpString As Long) As Long
    
    Private Declare Function SHGetFolderPath Lib "shfolder.dll" _
        Alias "SHGetFolderPathA" _
        (ByVal hwndOwner As Long, _
        ByVal nFolder As Long, _
        ByVal hToken As Long, _
        ByVal dwReserved As Long, _
        ByVal lpszPath As String) As Long
    
    Private Sub Command1_Click()
        Dim buff As String
        'Allocate buffer space
        buff = Space$(260)
        If SHGetFolderPath(Me.hwnd, &H5, -1, &H0, buff) = 0 Then
            Caption = TrimNull(buff)
        Else
            Caption = "Sorry - Not Found"
        End If
    End Sub
    
    Private Function TrimNull(startstr As String) As String
        TrimNull = Left$(startstr, lstrlenW(StrPtr(startstr)))
    End Function
    This code is a cut down version of the excellent code on Randy Birch's VBNet.
    www.mvps.org/

    Steve.

  4. #4
    Join Date
    Oct 2004
    Posts
    102
    My thanks to you both. I can see how both methods will be good to know for future reference.

    Thanks!

  5. #5
    Join Date
    Dec 2003
    Posts
    2,750
    Just an FYI with respect to SHGetFolderPath, it was added in Windows 2000 so if your app is to run on Windows 95, 98 or ME you have to distribute the SHFolder.dll file.

    Also, there was a security update that caused a glitch with this API. A hotfix or IE SP may be required.

    http://support.microsoft.com/default...b;en-us;303437

    Remember that just as the system environment variables rely on values stored in the Registry, so does SHGetFolderPath. If the user reconfigures his underlying My Documents folders improperly all bets are off.

    For this reason, if you really want to be thorough, use the Dir command to verify that the folder path returned is valid, regardless of what method you use. If it isn't valid then pop up a dialog requesting that the path be specified.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  6. #6
    Join Date
    Aug 2005
    Posts
    85
    Thanks for the update Paul.

    I was aware that the SHGetFolderPath was only available from 2000 onwards and should have pointed that out to Jac. But the dll is readily distributable and I have always thought it would return the folder, no matter what the user has done.

    Can you ellucidate further?

    Many Thanks,

    Steve.

Similar Threads

  1. Short cut keys in web pages?
    By Niels in forum Web
    Replies: 2
    Last Post: 11-15-2002, 11:54 AM
  2. Short Cut keys in WEB page
    By Sunil Menon in forum Web
    Replies: 1
    Last Post: 07-26-2002, 08:35 PM
  3. Replies: 0
    Last Post: 08-26-2001, 01:20 PM
  4. How to Create Short Cut in Startup Menu
    By Ashraf Chaudhry in forum VB Classic
    Replies: 2
    Last Post: 05-18-2001, 03:27 AM
  5. How to Create Short Cut in Startup Menu
    By Ashraf Chaudhry in forum VB Classic
    Replies: 0
    Last Post: 05-18-2001, 12:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center