|
-
August 26th, 2009, 06:31 AM
#1
[RESOLVED] browse path copying to textbox
Hi all,
I am making an application. Here one of the field is a picture. I need to browse to this picture folder from vb.net application and then save the path to a foxpro table. Something similar to what we have when a setup is run, we use to browse to target location and the path value will be there in the text box.
What is the approach to be tried out.
-
August 26th, 2009, 01:17 PM
#2
Re: browse path copying to textbox
You can use the OpenFileDialog for browsing to the file location and this dialog has a property called FileName that will tell you which file was selected along with the path.
-
August 26th, 2009, 04:03 PM
#3
Re: browse path copying to textbox
If you are looking for a file then the method above would be correct. If you are just wanting to browse for a folder then you would want to use the folderbrowsedialog instead.
Code:
Public Function GetFolder(Optional ByVal userPrompt As String = "Select Folder", Optional ByVal StartFolder As String = "c:\") As String
' First create a FolderBrowserDialog object
Dim FolderBrowserDialog1 As New FolderBrowserDialog
Dim ReturnString As String = ""
' Then use the following code to create the Dialog window
' Change the .SelectedPath property to the default location
With FolderBrowserDialog1
' Desktop is the root folder in the dialog.
.RootFolder = Environment.SpecialFolder.Desktop
' Select the start folder given as starting location.
.SelectedPath = StartFolder
' Prompt the user with a custom message.
.Description = userPrompt
If .ShowDialog = DialogResult.OK Then
' Return the selected folder if the user clicked on the OK button.
ReturnString = .SelectedPath
End If
End With
FolderBrowserDialog1 = Nothing
Return ReturnString
End Function
Last edited by DataMiser; August 26th, 2009 at 04:06 PM.
-
August 26th, 2009, 11:21 PM
#4
Re: browse path copying to textbox
thanks for the help. I was looking for the openfiledialog only.
While setting the filter here, i am facing a problem. I want to select only image files. So i wrote like this
Code:
openFileDialog1.Filter = "image (*.jpg) |*.bmp;*.gif|All files (*.*)|*.*"
but this is not showing the files with jpg extension, and i have to select All files option to view that. Where am i doing it wrong?
this is the complete code
Code:
Dim openFileDialog1 As System.Windows.Forms.OpenFileDialog
openFileDialog1 = New System.Windows.Forms.OpenFileDialog()
openFileDialog1.InitialDirectory = "D:\"
' openFileDialog1.Filter = "image (*.jpg) |*.bmp;*.rtf|(*.txt) |*.txt|(*.*) |*.*"
'openFileDialog1.Filter = " (*.jpg) |*.bmp;*.rtf|(*.txt) |*.txt|(*.*) |*.*"
openFileDialog1.Filter = "*.jpg|*.jpg |All files (*.*)|*.*"
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
locpic.Text = openFileDialog1.FileName
End If
Last edited by makdu; August 27th, 2009 at 04:55 AM.
-
August 27th, 2009, 01:11 PM
#5
Re: browse path copying to textbox
Your Filter property should ideally look like this
Code:
"JPG files (*.jpg)|*.jpg|Text files (*.txt)|*.txt|All files (*.*)|*.*"
-
August 27th, 2009, 07:35 PM
#6
Re: browse path copying to textbox
From MSDN:
Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*
Code:
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myStream As Stream = Nothing
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
myStream = openFileDialog1.OpenFile()
If (myStream IsNot Nothing) Then
' Insert code to read the stream here.
End If
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
Finally
' Check this again, since we need to make sure we didn't throw an exception on open.
If (myStream IsNot Nothing) Then
myStream.Close()
End If
End Try
End If
End Sub
-
August 28th, 2009, 11:19 PM
#7
Re: browse path copying to textbox
thank you all.
That worked with your suggestion
Tags for this Thread
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
|