Solved

Limit Selected File From OpenFileDialog

Posted on 2008-06-11
7
270 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting C# Objects into JSON file 7 65
VB.Net - CSV to Oracle table 4 52
Create XML 5 46
Want to create a userform that looks like the image provided 10 44
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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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