Solved

Limit Selected File From OpenFileDialog

Posted on 2008-06-11
7
274 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
Industry Leaders: 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 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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