CommonDialog and default file name 
Author Message
 CommonDialog and default file name

I'm using the CommonDialog control to provide a SaveAs dialog and would like
to set a default file name (not path) when the dialog opens. I tried setting
it using .FileTitle but this stopped the dialog opening. I would also like
to set the default path to My Documents but am aware that this location
varies across different versions of Windows, any ideas on how I can achieve
this?

Many thanks



Fri, 15 Oct 2004 01:57:23 GMT  
 CommonDialog and default file name
On Sun, 28 Apr 2002 18:57:23 +0100, "Geoff Soper"

Quote:

>I'm using the CommonDialog control to provide a SaveAs dialog and would like
>to set a default file name (not path) when the dialog opens. I tried setting
>it using .FileTitle but this stopped the dialog opening. I would also like
>to set the default path to My Documents but am aware that this location
>varies across different versions of Windows, any ideas on how I can achieve
>this?

You asketh for eth.. ;-)
I think there was an issue with this function on a platform..can't
remember though if it was real or which, see how you go.

Quick and dirty but tested. You may have to cater for possible
backslash fixing. ie: you don't want a backslash in front of the file
name if the folder evaluates to "C:\"...  

Option Explicit

Private Const CSIDL_DESKTOP = &H0
Private Const CSIDL_INTERNET = &H1
Private Const CSIDL_PROGRAMS = &H2
Private Const CSIDL_CONTROLS = &H3
Private Const CSIDL_PRINTERS = &H4
Private Const CSIDL_PERSONAL = &H5
Private Const CSIDL_FAVORITES = &H6
Private Const CSIDL_STARTUP = &H7
Private Const CSIDL_RECENT = &H8
Private Const CSIDL_SENDTO = &H9
Private Const CSIDL_BITBUCKET = &HA
Private Const CSIDL_STARTMENU = &HB
Private Const CSIDL_DESKTOPDIRECTORY = &H10
Private Const CSIDL_DRIVES = &H11
Private Const CSIDL_NETWORK = &H12
Private Const CSIDL_NETHOOD = &H13
Private Const CSIDL_FONTS = &H14
Private Const CSIDL_TEMPLATES = &H15
Private Const CSIDL_COMMON_STARTMENU = &H16
Private Const CSIDL_COMMON_PROGRAMS = &H17
Private Const CSIDL_COMMON_STARTUP = &H18
Private Const CSIDL_COMMON_DESKTOPDIRECTORY = &H19
Private Const CSIDL_APPDATA = &H1A
Private Const CSIDL_PRINTHOOD = &H1B
Private Const CSIDL_ALTSTARTUP = &H1D
Private Const CSIDL_COMMON_ALTSTARTUP = &H1E
Private Const CSIDL_COMMON_FAVORITES = &H1F
Private Const CSIDL_INTERNET_CACHE = &H20
Private Const CSIDL_COOKIES = &H21
Private Const CSIDL_HISTORY = &H22

Private Declare Function SHGetSpecialFolderPath _
   Lib "shell32.dll" _
   Alias "SHGetSpecialFolderPathA" _
   (ByVal hWnd As Long, _
   ByVal lpszPath As String, _
   ByVal nFolder As Integer, _
   ByVal fCreate As Boolean) As Long

Private Sub Command1_Click()
    Dim myDocPath As String
    myDocPath = Space$(512) ' this has to be at least 256 (MAXPATH)

    If SHGetSpecialFolderPath(0&, myDocPath, CSIDL_PERSONAL, _
        False) <> 0 Then
        myDocPath = Left$(myDocPath, InStr(myDocPath, Chr$(0)) - 1)
        CMD.FileName = Trim$(myDocPath)
    End If

    CMD.FileName = Trim$(myDocPath) & "\hello.txt"
    CMD.ShowSave
End Sub

Regards, Frank



Fri, 15 Oct 2004 03:11:19 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Long file names and CommonDialog

2. CommonDialog.ShowOpen VB4>>>Extracting Files Names under Multiselect

3. How to specify default file name ?

4. Saving a file with a default name.

5. Supplying Default File Name in Save window

6. show save as dialog with default doc path but current file name

7. Help setting default file names

8. default file name

9. CommonDialog.ShowPrinter changes default printer

10. HOWTO change default view of Commondialog

11. What printer is chosen in CommonDialog when not default

12. Default color in Commondialog.showcolor

 

 
Powered by phpBB® Forum Software