Simply reading a filename

J

John Duval

Hi Petrosky,
I'm not sure exactly what you're looking for -- do you want the user to
browse for a file on the system using a GUI? If so, then check out the
OpenFileDialog class. For example:

OpenFileDialog ofd = new OpenFileDialog();
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
string filename = ofd.FileName;
MessageBox.Show(filename);
}

John
 
A

Andy Bates

If you want to check that a file/directory exists then you can use the File
class:

using System.IO;

if (File.Exists(@"c:\test.dat"))...
if (Directory.Exists(@"c:\myfolder"))...

If you want information on the file (size, modify time etc.) then take a
look at the FileInfo class:

FileInfo fi = new FileInfo(@"c:\test.dat");
fi.Length

HTH

- Andy
 
S

Stoitcho Goutsev \(100\)

Petrosky,

I think you are looking for System.IO.Directory.GetFiles. This method can
look for files using wildcards.
 
P

Petrosky

Hello,
May I ask what built-in functions available out there in C# to search
for a particular filename input from the user at runtime ?
I am completely new to system thingies, so please help beginner. I
appreciate any answers from you.
 

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