.NET

Reply
Mentor
mgorecki
Posts: 401
Registered: ‎09-23-2004
Message 1 of 5 (397 Views)

Adding Options to The File Save As Dialog Box

397 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,

Mark

 

 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

 

Mentor
mgorecki
Posts: 401
Registered: ‎09-23-2004
Message 2 of 5 (363 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
Artvegas
Posts: 104
Registered: ‎04-21-2011
Message 3 of 5 (339 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:
http://through-the-interface.typepad.com/through_the_interface/2007/08/using-autocads-.html

 

Allowing a user to select from multiple file formats inside AutoCAD using .NET:
http://through-the-interface.typepad.com/through_the_interface/2009/08/allowing-a-user-to-select-fro...

 

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.

 

Art

Distinguished Contributor
Artvegas
Posts: 104
Registered: ‎04-21-2011
Message 4 of 5 (331 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.
Mentor
mgorecki
Posts: 401
Registered: ‎09-23-2004
Message 5 of 5 (309 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community