Solved

Limit Selected File From OpenFileDialog

Posted on 2008-06-11
7
276 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
Technology Partners: 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

728 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