Solved

Limit Selected File From OpenFileDialog

Posted on 2008-06-11
7
266 Views
Last Modified: 2009-07-29
I have the following that allows the user to select an image from just about anywhere.  I would like to limit the selection to be from only one particular directory on a network.  How can this be done?  Here is the current code:

 Dim ofdBox As New OpenFileDialog
        If ofdBox.ShowDialog() = DialogResult.OK Then
            t1.Text = ofdBox.FileName
            PictureBox1.ImageLocation = t1.Text
        Else
            MsgBox("User Has Canceled", MsgBoxStyle.Information, Application.ProductName)
        End If
0
Comment
Question by:H-SC
7 Comments
 
LVL 14

Expert Comment

by:raja_ind82
ID: 21763617
ofdBox.Filter="All Formats|*.JPG,*.TIF|JPEG (*.JPG)|*.JPG|TIFF (*.TIF)|*.TIF"
ofdBox.Filter = "Flash Movie(*.swf)|*.swf"

Regards,
M.Raja
0
 
LVL 1

Author Comment

by:H-SC
ID: 21763734
M.Raja,

I am looking to limit the user to only select the file from a particular network folder, and not to limit the extension/file type  
0
 
LVL 25

Expert Comment

by:apeter
ID: 21763735
you have InitialDirectory Property. Gets or sets the initial directory displayed by the file dialog box . Later the user can move to any folder he wants and we can't restrict only to one folder.

Dim ofdBox As New OpenFileDialog
        ofdBox.InitialDirectory = "C:\" 'it show "c:" folder initially.
        If ofdBox.ShowDialog() = DialogResult.OK Then
            t1.Text = ofdBox.FileName
            PictureBox1.ImageLocation = t1.Text
        Else
            MsgBox("User Has Canceled", MsgBoxStyle.Information, Application.ProductName)
        End If
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:H-SC
ID: 21764104
M.Raja,

I think that will work...can I put a "Like" condition on the textBox after TextChanges to look at t1.text for "C:\" ?
0
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 21764161
try this code.
just change the directory name to where you want to go
   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() = DialogResult.OK Then

            'Check which dir you are in

            If Not openFileDialog1.FileName.StartsWith("C:\WINDOWS") Then

                MessageBox.Show("Not the right directory")

            End If

        End If

Open in new window

0
 
LVL 14

Expert Comment

by:raja_ind82
ID: 21767095
Before this you have to check the permission to access that machine.

openFileDialog1.InitialDirectory = "\\RemoteComputerName\c$"

Regards,
M.Raja
0
 
LVL 1

Author Comment

by:H-SC
ID: 21771863
planocz,

That worked perfect!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now