Get OpenFileDialog filename path...

  • Thread starter Thread starter SpreadTooThin
  • Start date Start date
S

SpreadTooThin

After I select a file with the OpenFileDialog, I get the file name
with .FileName,
but I want to know the drive and path where that file is.
What function, method, class can I use in C# to get the drive and
path?
 
After I select a file with the OpenFileDialog, I get the file name
with .FileName,
but I want to know the drive and path where that file is.
What function, method, class can I use in C# to get the drive and
path?


You can use the Path.GetDirectoryName to get the path(directory)
and you can use Path.VolumeSeparatorChar to split the filename and use
the first part. There could be better way of doing this.
 
You can use the Path.GetDirectoryName to get the path(directory)
and you can use Path.VolumeSeparatorChar to split the filename and use
the first part. There could be better way of doing this.

Path.GetDirectoryName?
I don't know where Path is what class is that?
..
 
After I select a file with the OpenFileDialog, I get the file name
with .FileName,
but I want to know the drive andpathwhere that file is.
What function, method, class can I use in C# to get the drive andpath?

OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "C# Help";
fdlg.InitialDirectory = @"c:\";
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
string dirName =
System.IO.Path.GetDirectoryName(fdlg.FileName);
string drive =
dirName.Split(System.IO.Path.VolumeSeparatorChar)[0];
MessageBox.Show(dirName);
MessageBox.Show(drive);
}

Hopefully this should help...
 
After I select a file with the OpenFileDialog, I get the file name
with .FileName,
but I want to know the drive andpathwhere that file is.
What function, method, class can I use in C# to get the drive andpath?

            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = "C# Help";
            fdlg.InitialDirectory = @"c:\";
            fdlg.Filter = "All files (*.*)|*.*|All files (*..*)|*.*";
            fdlg.FilterIndex = 2;
            fdlg.RestoreDirectory = true;
            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                string dirName =
System.IO.Path.GetDirectoryName(fdlg.FileName);
                string drive =
dirName.Split(System.IO.Path.VolumeSeparatorChar)[0];
                MessageBox.Show(dirName);
                MessageBox.Show(drive);
            }

Hopefully this should help...

Thats great thanks!
Remindes me of borland fnsplit, which gave you drive, path filename
and extension.
 
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "C# Help";
fdlg.InitialDirectory = @"c:\";
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
string dirName =
System.IO.Path.GetDirectoryName(fdlg.FileName);
string drive =
dirName.Split(System.IO.Path.VolumeSeparatorChar)[0];
MessageBox.Show(dirName);
MessageBox.Show(drive);
}
Hopefully this should help...

Thats great thanks!
Remindes me of borland fnsplit, which gave you drive, path filename
and extension.

I hope you got how to do it...

-Cnu
 
Back
Top