CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Location
    Jakarta, Indonesia
    Posts
    596

    how to save file to Desktop?

    hi,

    i like to export a file to .xls that located in Desktop
    but if the UserName or WindowLogin or ComputerName(not sure which one is the correct ) change the the path will also changed
    ex : "C:\Documents and Settings\eRiCk\Desktop"
    "C:\Documents and Settings\Vaio\Desktop"
    how to solve this?

    thanks

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: how to save file to Desktop?

    You can invoke the GetUserProfileDirectory(...) located in Userenv.lib to abtain the directory like "C:\Documents and Settings\Joe".

    - petter

  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: how to save file to Desktop?

    You can use the SHGetFolderPath API to get the desktop folder.

    Code:
    Private Const CSIDL_DESKTOPDIRECTORY As Long = &H10
    Private Declare Function SHGetFolderPath Lib "shfolder" _
            Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, _
            ByVal nFolder As Long, ByVal hToken As Long, _
            ByVal dwFlags As Long, ByVal pszPath As String) As Long
    
    Private Sub Command1_Click()
    
        Dim strPath As String, lRet As Long
    
        strPath = String(255, 0)
        lRet = SHGetFolderPath(0, lngCSIDL, 0, SHGFP_TYPE_CURRENT, strPath)
    
        strPath = Left$(strPath, InStr(1, strPath, Chr(0)) - 1)
        MsgBox strPath
    
    End Sub
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured