JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Save File Dialogs

You can use the SaveFileDialog class to display a Save File dialog and get the name of the file the user wants to save data to. You can see an example in the SaveFileDialog example on the CD-ROM. Here's how that works in code; I'm checking the return value from the ShowDialog method, and if it's anything but DialogResult.Cancel, I display the filename that the user selected in a message box:

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    If SaveFileDialog1.ShowDialog <> DialogResult.Cancel Then
        MsgBox("You chose " & SaveFileDialog1.FileName)
    End If
End Sub

You can use the CreatePrompt property to display a prompt asking the user if a file that does not exist should be created, and the OverwritePrompt property to ask the user if an existing file should be overwritten.

You can see the Save File dialog that the SaveFileDialog example from the CD-ROM creates in Figure 9.4.


Don't forget that you can set the dialog box's title with the Title property in case you don't want it just to say "Save As".

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor