?
Solved

Limit Selected File From OpenFileDialog

Posted on 2008-06-11
7
Medium Priority
?
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

770 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