Select file from dialog box

R

RP

I have a text box in which I need the path of the file a user selects
from the dialog box. I also want that the dialog box is filtered to
show only image files, and when the user selects this file, the path
of the file is shown on the text box.
 
J

Jon Skeet [C# MVP]

I have a text box in which I need the path of the file a user selects
from the dialog box. I also want that the dialog box is filtered to
show only image files, and when the user selects this file, the path
of the file is shown on the text box.

It's not clear whether you're talking about a web application or a
WinForms application, but have you looked at the OpenFileDialog class?

Jon
 
H

harborsparrow

Try something like this:

OpenFileDialog openFileDialog1 = null;
string newfilespec;
try
{

openFileDialog1 = new OpenFileDialog();

openFileDialog1.Title = "Select a text file to add to
the search list";
openFileDialog1.InitialDirectory = "C:\\";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All
files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top