BUG: SaveFileDialog object returns "Cancel" whether or not you overwrite an existing file (327213)



The information in this article applies to:

  • Microsoft .NET Framework
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual Basic .NET (2003)

This article was previously published under Q327213

SYMPTOMS

When you call the ShowDialog method of a SaveFileDialog object from the Sub Main procedure, you receive DialogResult.CANCEL whether or not you choose to overwrite an existing file.

RESOLUTION

To avoid this problem, call the ShowDialog method from outside the Sub Main procedure.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. In Visual Basic .NET, create a new Console Application project.
  2. In Project Explorer, right-click References, and then click Add Reference.
  3. Click .NET Framework.
  4. In the Component Name list, click System.Windows.Forms.Dll, click Select, and then click OK.
  5. Above the Module section of Module 1, enter the following code:
    Imports System.Windows.Forms
    					
  6. In the Sub Main procedure, enter the following code:
    Dim myDialog As New SaveFileDialog()
    MessageBox.Show(myDialog.ShowDialog.ToString)
    					
  7. On the Debug menu, click Start to run the application.
  8. In the Save As dialog box, select any existing file, and then click Save.
  9. In the dialog box that prompts you with the question "Do you want to replace the existing file," click Yes.

    Notice that the message box displays the CANCEL DialogResult.
  10. Start the application again. Repeat step 8, but in the dialog box that prompts you with the question "Do you want to replace the existing file," click No.

    Notice that the message box displays the CANCEL DialogResult.

Modification Type:MinorLast Reviewed:1/23/2006
Keywords:kbvs2005doesnotapply kbvs2005swept kbvs2002sp1sweep kbbug kbnofix KB327213