Hello all, this is my first post here on DANIWEB.

I am looking for a way to display the directory of file opened with OpenDialog.

I can get the entire path (including file name) using:
TextBox1.Text = OpenFile.FileName

The result would be something like
C:\Documents and Settings\Administrator\Desktop\Test.txt

What I am really looking for is a way to get only the directory like:
C:\Documents and Settings\Administrator\Desktop

Does anyone have a suggestions

Thanks

Here's two ways to do it.

Straight from the OpenFileDialog's property:

TextBox1.Text = OpenFile.InitialDirectory

or by using GetDirectoryName method from the Path class:

TextBox1.Text = Path.GetDirectoryName(OpenFile.FileName)

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.