Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OpenFileDialog 1

Status
Not open for further replies.
May 22, 2003
42
US
Hi

I'm trying to pass the file name from the OpenFileDialog box to a batch file as a string. I'm able to bring up the dialog box and select the file but I'm not sure about declaring the file name and passing it as a string. Any help would be greatly appreciated.

Thanks in advance.

Here's what I have so far:

OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
fileName = OpenFileDialog1.FileName
End If

 
How about
Code:
Dim myName As String = ""
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
   myName = OpenFileDialog1.FileName
End If

But be sure that the multiple file selection of OpenFileDialog1 is false.

Regards.
 
I think the OP is asking how to actually use the returned file name in opening a batch file.

Try this:

OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
fileName = OpenFileDialog1.FileName
End If

Dim p2 As New System.Diagnostics.ProcessStartInfo
p2.FileName = "C:\BatchFile.bat"
p2.UseShellExecute = True
p2.Arguments = fileName
System.Diagnostics.Process.Start(p2)


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks Mansil!

This worked like a charm.


Dim myName As String = ""
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
myName = OpenFileDialog1.FileName
End If
 
I'm not out of the woods yet. The string is returned with the full file path. I need to parse the string for the file name only before passing it to a batch file. Any ideas?

Thanks
 
Well, use the System.IO.Path.GetFileName:
Code:
System.IO.Path.GetFileName(myName)

And thank's for the star.
 
Hi Mansil

I'm sorry but I'm not sure where System.IO.Path.GetFileName(myName) fits in? Here is my code below:

Dim AppName As String
If rb_Install_msi.Checked = True Then
OpenFileDialog1.InitialDirectory = "RInstaller"
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = ".msi|*.msi"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
AppName = OpenFileDialog1.FileName
Shell("RInstaller\msi.bat " & " " & AppName & " " & Me.t_HostName.Text, AppWinStyle.NormalFocus, False)
End If
End If

Thanks
 
Something like
Code:
AppName = [blue]System.IO.Path.GetFileName([/blue]OpenFileDialog1.FileName[blue])[/blue]

 
Mansil

Thanks again! that was exactly what I was looking for. I can't thank you enough. If I could give you 2 stars I would.
Can you please reccomend any books or training on vb.net?
As you can see I'm a newbie, and would like to learn more on the subject.
 
tony,
Thank's for your apraisal. Unfortunately, I cannot recommend you any book for I do not have any. I believe there are tons of free VBNet training site on Google search. Or, stick around here in Tek-tips. You'll enjoy it as I do.

Thank's again.
 
Hi Mansil

I'll take your advice and stick around. Hey do you know of a way to have an application check for an update every time it launches? I've tried ClickOnce with no success because of it's limitaions, and don't understand how the Application Updater block works?

Tony
 
Hi tonyflora63,
I would advise you to start a new thread for that. Very few people will come answer this question here when the main threa states OpenFileDialog.
Hope it'll eventually help you.

---
[tt][COLOR=white Black]MASTA[/color][COLOR=Black lightgrey]KILLA[/color][/tt] [pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top