4 Replies - 1207 Views - Last Post: 02 March 2011 - 08:59 AM Rate Topic: -----

#1 RandomlyKnighted   User is offline

  • D.I.C Lover
  • member icon

Reputation: 119
  • View blog
  • Posts: 1,384
  • Joined: 14-January 10

Save dialog gives empty path is not legal error

Posted 02 March 2011 - 08:13 AM

Hey everyone, I'm working on a Save As dialog for my program. I almost have it working I'm just stuck on one part.

For a while I hit the cancel button in the Save dialog and it would give me an "Empty path is not legal" error. So I used the code below to verify that a file name was entered before saving.

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // Get file name from the user.
                string name = saveFileDialog2.FileName;
                File.WriteAllText(name, buffer);
            }



Once I did that I could go to the Save As dialog and hit Cancel without actually having a File name entered into the dialog and it doesn't give me the error. However, I can put a File Name into the Save dialog and then hit the Save button and it gives me the same error. I don't understand why I get this, can someone please explain?

Is This A Good Question/Topic? 0
  • +

Replies To: Save dialog gives empty path is not legal error

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Save dialog gives empty path is not legal error

Posted 02 March 2011 - 08:27 AM

Because you are showing savefiledialog1 and checking against savefiledialog2,
They are two different instances of the savefiledialog class, just as my Dodge Ram is a different instance of the Dodge Ram class than my neighbor's Dodge Ram.

This post has been edited by tlhIn`toq: 02 March 2011 - 08:28 AM

Was This Post Helpful? 1
  • +
  • -

#3 RandomlyKnighted   User is offline

  • D.I.C Lover
  • member icon

Reputation: 119
  • View blog
  • Posts: 1,384
  • Joined: 14-January 10

Re: Save dialog gives empty path is not legal error

Posted 02 March 2011 - 08:32 AM

Wow, something so simple. I can't believe I overlooked that. Thanks again!
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Save dialog gives empty path is not legal error

Posted 02 March 2011 - 08:39 AM

No worries. Proofreading ones own work is something I struggle with all the time. Because I wrote it I know what it is supposed to say. Therefore when I read it back I fill in reality with intention. Most people do it. But when we look at someone's else work that is totally new to us, we read it as such.
Was This Post Helpful? 0
  • +
  • -

#5 RandomlyKnighted   User is offline

  • D.I.C Lover
  • member icon

Reputation: 119
  • View blog
  • Posts: 1,384
  • Joined: 14-January 10

Re: Save dialog gives empty path is not legal error

Posted 02 March 2011 - 08:59 AM

Yeah, I know what you mean. I read it no telling how many times. I get proofreading my own work just isn't my thing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1