?
Solved

File Search&Select

Posted on 2004-11-03
12
Medium Priority
?
192 Views
Last Modified: 2010-04-23
ive got a program that retreives info from a text file (data.txt) that is stored in my /bin directory of my VB.net project.

im trying to create a button to bring up a normal windows file explorer to search and then select the appropriate file (whether its stored on floppy,flash,cd,c: etc.).

can i do this in .net?

and if so, how?
0
Comment
Question by:minichicken
  • 6
  • 4
  • 2
12 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 12486078
Do you mean you want to find data.txt
or
Read the Text file and go get the file that is named in the data.txt?
0
 
LVL 12

Author Comment

by:minichicken
ID: 12486171
its just a path.

basically the 'browse' for the file must store the path so the function to edit the file will know where the file is.

eg. someone wants to run a spell check on a data.txt and he/she has it on a stiffy disk/flash drive..
      the program must browse and find where this file is stored to run the spell-check

hope this helps!
0
 
LVL 27

Expert Comment

by:planocz
ID: 12486406
I think it will still be faster for the user to find the file with this dialog.

 Public sFileName as string
 
 Public Sub OpenFile()
        ' Create the OpenFileDialog object
        Dim myOpenFileDialog As New OpenFileDialog
        With myOpenFileDialog
            .CheckFileExists = True
            .DefaultExt = "txt"
            .InitialDirectory = "c:\"
            .Multiselect = False
        End With
        ' Use the OpenFileDialog and put the path and name of the selected file in a var.
        If myOpenFileDialog.ShowDialog = DialogResult.OK Then
            sFileName = myOpenFileDialog.FileName
        End If
    End Sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Author Comment

by:minichicken
ID: 12486506
how do i use the "OpenFileDialog" in vb.net?
0
 
LVL 27

Expert Comment

by:planocz
ID: 12486846
put in new app.


Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(200, 180)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(68, 32)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Open File"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private sFileName As String
    Private Sub OpenFile()
        ' Create the OpenFileDialog object
        Dim myOpenFileDialog As New OpenFileDialog
        With myOpenFileDialog
            .CheckFileExists = True
            .DefaultExt = "txt"
            .Filter = "Text files(*.txt)|*.txt"
            .InitialDirectory = "c:\"
            .Multiselect = False
        End With
        ' Use the OpenFileDialog and put the path and name of the selected file in a var.
        If myOpenFileDialog.ShowDialog = DialogResult.OK Then
            sFileName = myOpenFileDialog.FileName
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFile()
    End Sub
End Class
0
 
LVL 12

Author Comment

by:minichicken
ID: 12486904
thanks alot man!

sorry, just one more question:

will this function give the file path (eg a:/expert/data.txt) as a String variable?
0
 
LVL 27

Accepted Solution

by:
planocz earned 1500 total points
ID: 12486928
Yes the var sFileName will have the full path and name of the file.
0
 
LVL 2

Expert Comment

by:Silversoft
ID: 12487351
you wouldnt be able to help me with some cool form design? (ie transparecy, shape-alteration, or plain old cool ****?)
0
 
LVL 27

Expert Comment

by:planocz
ID: 12487509
Silversoft  do you work with minichicken?
Or are you minichicken?

0
 
LVL 12

Author Comment

by:minichicken
ID: 12487584
Hi planocz

I (minichicken) logged on Silversoft's machine last time and forgot to logout.
And we work together.... :)
0
 
LVL 27

Expert Comment

by:planocz
ID: 12487599
to help get you started here is some links...

Here is where I found good examples for getting started in VB.Net

.....http://msdn.microsoft.com/vbasic/downloads/samples/101samples.aspx

Link for ASP programs...

http://msdn.microsoft.com/asp.net/downloads/kits/default.aspx 
0
 
LVL 2

Expert Comment

by:Silversoft
ID: 12487647
yeah we all the same
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question