Posts: 414
Registered: ‎09-23-2004
Message 1 of 5 (444 Views)

Adding Options to The File Save As Dialog Box

444 Views, 4 Replies
06-07-2012 02:43 PM

Hello, I have the following function that opens the File "Save As" dialog box.  It gets fed a drawing number and allows the users to browse to a folder where they want to save it.  The problem is when a file already exists with the same name.  A message box pops up letting the user know that the file already exists and do they want to overwrite it.  The can pick yes to overwrite, but it doesn't really overwrite the old file, it seems like it opens it and then crashes when the rest of the program tries to run.

What I want to do is create a loop to determine if the file already exists.  If it does not exist, then save the path and drawing name as usual. 

If the drawing exists, I want to pop up a dialog giving two options; Overwrite, or Rename the current drawing.  If they pick Overwrite, I can have the program delete the old existing drawing and then just save this one.  If they pick Rename it will loop back to the "Save As" dialog giving the user the ability to change their drawing name (like add a "-1" to it.

Any help will be greatly appreciated.


Best regards,



 Public Function GetFilePathAndName(ByVal dwgNumber)
        podDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
        podDB = podDWG.Database
        podEd = podDWG.Editor
        podPSO.InitialDirectory = "W:\Work_in_Process"
        podPSO.InitialFileName = dwgNumber
        podPSO.Filter = "AutoCAD DWG Files|*.dwg"
        podPFR = podEd.GetFileNameForSave(podPSO)
        Select Case podPFR.Status
            Case EditorInput.PromptStatus.OK
                SaveDwgName = podPFR.StringResult
            Case EditorInput.PromptStatus.Cancel
                MsgBox("User Cancelled.")
        End Select
        Return SaveDwgName
    End Function


Posts: 414
Registered: ‎09-23-2004
Message 2 of 5 (410 Views)

Re: Adding Options to The File Save As Dialog Box

06-08-2012 08:22 AM in reply to: mgorecki

I guess what I want to know is, is there a way to turn off the automatic message that pops up saying "The drawing already exists, do you want to overwrite?"

I want to supply my own message.

Distinguished Contributor
Posts: 104
Registered: ‎04-21-2011
Message 3 of 5 (386 Views)

Re: Adding Options to The File Save As Dialog Box

06-10-2012 12:47 PM in reply to: mgorecki

The dialog shouldn't actually do anything with the file. It simply returns a file name string. The dialog shows the message you mentioned if a file with the same name already exists. This should only effect the returned PromptFileNameResult.Status property. It's probably a good idea to check the PromptFileNameResult.ReadOnly property before you try to save the file.


If there is a crash it will have something to do with your code and how it accesses the existing file (i.e. a file sharing issue where the file is already open and cannot be accessed for save). It could be open by anyone if you are on a network, so you need to program defensively for this.


Do you know about the Autodesk.AutoCAD.Windows.SaveFileDialog class? The ObjectARX docs mention a SaveFileDialogFlags.DoNotWarnIfFileExists enum which you pass into the SaveFileDialog constructor.


If you haven't used the SaveFileDialog class before then you can check out the following posts. There are some slight differences between the two that are discussed in detail.


Using AutoCAD's file selection dialog from .NET:


Allowing a user to select from multiple file formats inside AutoCAD using .NET:


I'm sure this will do the trick for you. The only other alternative I can think of is to use a standard .NET SaveFileDialog class from either windows forms or wpf.



Distinguished Contributor
Posts: 104
Registered: ‎04-21-2011
Message 4 of 5 (378 Views)

Re: Adding Options to The File Save As Dialog Box

06-10-2012 01:06 PM in reply to: Artvegas
One other thing... i don't know if it's possible to show your own message on top of the save dialog (i.e. while it is still open). Same goes for the standard .NET dialogs. I think you'd have to create your own save dialog which doesn't sound fun. But really you shouldn't need to go there if you are using the AutoCAD API dialogs correctly.
Posts: 414
Registered: ‎09-23-2004
Message 5 of 5 (356 Views)

Re: Adding Options to The File Save As Dialog Box

06-11-2012 08:04 AM in reply to: Artvegas

Hi Artvegas,

Thanks for the links.  I believe what was happening was that if the file existed already, and the user pick "Yes" to overwrite, the file was being opened.  Since the program creates blocks (and the blocks would already be created in the opened drawing) it would crash the program when AutoCad would ask if they wanted to re-define the block.

I've decided to go the simple route and just have the program delete the drawing name that the user enters before it saves the new drawing.  If the drawing already exists, then it's deleted, if not, then it does nothing.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!