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 Mike Lewis 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.

trk1616b

MIS
May 25, 2005
20
0
0
US
I'm using an OpenFileDialog box on my app. When the form loads, i want the system to go and see if a hard coded path exists AND if a hard coded file exists in that path. If the file exists, I want to assign the file to OpenFileDialog.FileName. Anyone know any good ways to do this? I've tried several things, but i cannot get it to verify the path and file exist.

THanks!
 
I would be quite interested to know if any answers given to your previous questions have been of any help to you.

[vampire][bat]
 
Absolutely, they have been great. The feedback you helped with yesterday solved my problem. Thank you.
 
You could try something like:

Code:
  Private HardCodedPath As String = "c:\data"
  Private HardCodedFilename As String = "MyFile.txt"

  Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

    OpenFileDialog1.FileName = ""
    If IO.Directory.Exists(HardCodedPath) Then
      If IO.File.Exists(HardCodedPath + "\" + HardCodedFilename) Then
        OpenFileDialog1.FileName = HardCodedPath + "\" + HardCodedFilename
      Else
        MessageBox.Show(HardCodedFilename + " does not exist")
      End If
    Else
      MessageBox.Show(HardCodedPath + " does not exist")
    End If
    If OpenFileDialog1.FileName <> "" Then
      OpenFileDialog1.ShowDialog()
    Else
      'do something else
    End If

  End Sub


Hope this helps.

Not only does it help those who reply if you say whether or not the reply was useful, it also helps others with a similar problem as they can see straight away that the answer worked. Additionally, if you come up with another solution, it helps everyone if you post that.

[vampire][bat]
 
I'm glad it helped.

Thanks for the star, but that wasn't so much the point. What is important, as I said above, is that you do take the time to comment on the replies you receive. That is what makes Tek-Tips so useful for everyone.

Thanks again.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top