-
Aug 4th, 2010, 12:15 PM
#1
Thread Starter
Junior Member
[RESOLVED] Getting application title using openFileDialog
Currently, my problem is that I can't display the application name that I've chosen using openFileDialog. In this case, I'm not referring to the FileName where it displays the full path. I just want the last segment of the FileName, which is the targeted application name.
Perhaps you can work on this code snippet:
vb.net Code:
Imports System.IO Imports System.Diagnostics ' Public Partial Class MainForm Public Sub New() ' The Me.InitializeComponent call is required for Windows Forms designer support. Me.InitializeComponent() ' ' TODO : Add constructor code after InitializeComponents End Sub Sub Button1Click(ByVal sender As Object, ByVal e As EventArgs) OpenFileDialog1.Title = "Please Select a File" OpenFileDialog1.InitialDirectory = "C:temp" OpenFileDialog1.ShowDialog() End Sub Sub OpenFileDialog1FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Dim strm As System.IO.Stream strm = OpenFileDialog1.OpenFile() TextBox1.Text = OpenFileDialog1.FileName.ToString() End Sub 'This section displays the full path in a textbox. Then Process.Start event takes place at button2. Sub Button2Click(ByVal sender As Object, ByVal e As EventArgs) Process.Start(OpenFileDialog1.FileName) ' Below Process.Start, I want the name of the targeted application to be displayed in a label after this button click event. End Sub End Class[CODE][/CODE]
And of course, thank you if you've taken the time to help me! (:
EDIT: I've found some leads which I think can be used but I do not know how to go about applying it here.
Links:
http://www.freevbcode.com/ShowCode.asp?ID=5558
http://bytes.com/topic/visual-basic-...w-get-filename
EDIT2: Problem solved. (By adding this code snippet)
Code:
iPos = 1
Do
iPos = InStr(iPos, sPath, "\")
If iPos = 0 Then Exit Do
iPos = iPos + 1
iPosSave = iPos - 1
Loop
label1.Text = (Trim(Mid(sPath, iPosSave + 1)))
]
Last edited by metalm3; Aug 4th, 2010 at 12:34 PM.
-
Aug 4th, 2010, 12:34 PM
#2
Addicted Member
Re: Getting application title using openFileDialog
io.path.getfilename(openfiledialog1.filename)
or
io.path.getfilenamewithoutextension(openfiledialog1.filename)
-
Aug 4th, 2010, 12:35 PM
#3
Re: Getting application title using openFileDialog
When dealing with things like this, it's best to read the documentation first.
I wasn't sure, so I went to MSDN and typed in 'OpenFileDialog'
I read through the properties and saw 'SafeFileName'
Originally Posted by MSDN
Gets the file name and extension for the file selected in the dialog box. The file name does not include the path.
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Aug 4th, 2010, 12:36 PM
#4
Thread Starter
Junior Member
Re: Getting application title using openFileDialog
Originally Posted by Spirited Machine
io.path.getfilename(openfiledialog1.filename)
or
io.path.getfilenamewithoutextension(openfiledialog1.filename)
Hey there. I've resolved the problem. But yours is a much faster and instant way! Thanks! (:
-
Aug 4th, 2010, 12:37 PM
#5
Re: Getting application title using openFileDialog
Originally Posted by Spirited Machine
io.path.getfilename(openfiledialog1.filename)
or
io.path.getfilenamewithoutextension(openfiledialog1.filename)
That creates unnecessary overhead. The OP should just use the 'SafeFileName' property of the OpenFileDialog.
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Aug 4th, 2010, 12:37 PM
#6
Thread Starter
Junior Member
Re: Getting application title using openFileDialog
Originally Posted by weirddemon
When dealing with things like this, it's best to read the documentation first.
I wasn't sure, so I went to MSDN and typed in ' OpenFileDialog'
I read through the properties and saw ' SafeFileName'
I did read that, but didn't pay much attention to that property. And I've learned my lesson. (: Thanks for the help!
-
Aug 4th, 2010, 12:41 PM
#7
Thread Starter
Junior Member
Re: Getting application title using openFileDialog
Originally Posted by weirddemon
That creates unnecessary overhead. The OP should just use the 'SafeFileName' property of the OpenFileDialog.
I went to see the declaration code snippet but I'm not sure on how to apply it. What's the "Get" there for?
vb.net Code:
[CODE]'Declaration <BrowsableAttribute(False)> _ Public ReadOnly Property SafeFileName As String Get [/CODE]
EDIT:
Oops. Mental block earlier on. Got it with OpenFileDialog1.SafeFileName. Thanks (:
-
Aug 4th, 2010, 12:58 PM
#8
Re: Getting application title using openFileDialog
Originally Posted by metalm3
I went to see the declaration code snippet but I'm not sure on how to apply it. What's the "Get" there for?
vb.net Code:
[CODE]'Declaration
<BrowsableAttribute(False)> _
Public ReadOnly Property SafeFileName As String
Get
[/CODE]
EDIT:
Oops. Mental block earlier on. Got it with OpenFileDialog1.SafeFileName. Thanks (:
Great. Please mark the thread resolved by selecting it from the Thread Tools menu located near the top of the page.
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Aug 5th, 2010, 07:12 AM
#9
Addicted Member
Re: Getting application title using openFileDialog
Originally Posted by weirddemon
That creates unnecessary overhead. The OP should just use the 'SafeFileName' property of the OpenFileDialog.
Well I just learned something new today too. I didn't know that property existed. Thanks.
-
Aug 5th, 2010, 07:26 AM
#10
Re: Getting application title using openFileDialog
Originally Posted by Spirited Machine
Well I just learned something new today too. I didn't know that property existed. Thanks.
No problem. Like JMC 'says', when in doubt, read the documentation
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|