2 Replies - 444 Views - Last Post: 20 January 2013 - 04:55 AM Rate Topic: -----

#1 kamikazehighland  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 13

Path.GetFileName(saveFileDialog1.FileName) As String

Posted 18 January 2013 - 08:07 PM

This crashes:
Dim filename As String = System.IO.Path.GetFileName(saveFileDialog1.FileName)
file.Save(filename)

This works fine:
Dim filename As String = System.IO.Path.GetFileName(saveFileDialog1.FileName)
Dim filename2 As String = "filename"
file.Save(filename2)

When the first crashes, however, and I check the string names in the output or "Autos", filename and filename2 match. What's the problem?

Is This A Good Question/Topic? 0
  • +

Replies To: Path.GetFileName(saveFileDialog1.FileName) As String

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Path.GetFileName(saveFileDialog1.FileName) As String

Posted 18 January 2013 - 08:30 PM

What happens if you try:
   Dim fname As String = System.IO.Path.GetFileName(saveFileDialog1.FileName)
   file.Save(fname)


The fact that filename is a property of file may be causing a problem.
I find it pays to avoid property, method, control etc. names for variables.

This post has been edited by lar3ry: 18 January 2013 - 08:30 PM

Was This Post Helpful? 0
  • +
  • -

#3 kamikazehighland  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 13

Re: Path.GetFileName(saveFileDialog1.FileName) As String

Posted 20 January 2013 - 04:55 AM

Thanks! I found the problem was actually that the file was in use, and I could save to any file name other than the one I chose in the save file dialog. I have fixed the problem and it works.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1