Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting a file name form a save dialoge
#1
Hey, I was just wondering how to get the actual fine name(not including the path) of a file chosen from a save file dialog. If anyone knows, help would be much appreciated! thanks!
#2
Do you mean like finding the actual file of your program inside your computer files?
#3
I wrote a small application for saving a file. Here is the code:
[code2=vbnet]Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SaveFile As New SaveFileDialog
SaveFile.Title = "Save file"
SaveFile.Filter = "Text files (*.txt)|*.txt"
SaveFile.InitialDirectory = "C:\"
SaveFile.RestoreDirectory = True
Dim d = SaveFile.ShowDialog()

If d = DialogResult.OK Then
Try
Dim DocumentTitle As String = System.IO.Path.GetFileName(SaveFile.FileName)
Me.Text = DocumentTitle & " - Software Name"

Dim W As New System.IO.StreamWriter(SaveFile.FileName)
W.Write(RichTextBox1.Text)
W.Close()
Catch ex As Exception
MessageBox.Show("You have encountered an error." & Environment.NewLine & Environment.NewLine & "ERROR: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
End Class[/code2]

Since you don't need that, here is the line that you need:
[code2=vbnet]Dim DocumentTitle As String = System.IO.Path.GetFileName(SaveFile.FileName)
Me.Text = DocumentTitle & " - Software Name"[/code2]
Also known as Rocketalypse.
System.out.println("I prefer Java.");
#4
You can also use
[code2=vbnet]System.IO.Path.GetFileNameWithoutExtension()[/code2]

In order to get the file name without the ".exe", etc!
My Blog | My Setup | My Videos | Have a wonderful day.


Possibly Related Threads…
Thread Author Replies Views Last Post
  Rename application file brco900033 3 14,847 10-15-2013, 12:03 AM
Last Post: brandonio21
  I am getting problem with brandonio's registration form... mnxford 1 9,177 03-27-2013, 10:55 AM
Last Post: mnxford
  i am getting a problem with brandonio's login form mnxford 1 9,110 03-27-2013, 10:55 AM
Last Post: mnxford
  Copy file to clipboard brco900033 4 17,385 11-04-2012, 12:17 AM
Last Post: brandonio21
  How do I fill my form with MySQL data based on Combobox? kismetgerald 8 26,732 10-14-2012, 09:05 PM
Last Post: brandonio21
  Save Help manishshrestha60 2 11,560 09-14-2012, 11:48 PM
Last Post: Vinwarez
  External Settings File brco900033 1 8,782 11-04-2011, 02:47 PM
Last Post: brandonio21
  Form/Application Store PsychicShadow 2 12,428 06-02-2011, 09:16 PM
Last Post: xolara

Forum Jump:


Users browsing this thread: 1 Guest(s)