Get OpenFileDialog filename path...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SpreadTooThin

    Get OpenFileDialog filename 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?
  • parez

    #2
    Re: Get OpenFileDialog filename path...

    On Jun 27, 10:31 pm, SpreadTooThin <bjobrie...@gma il.comwrote:
    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.GetDirecto ryName to get the path(directory)
    and you can use Path.VolumeSepa ratorChar to split the filename and use
    the first part. There could be better way of doing this.

    Comment

    • SpreadTooThin

      #3
      Re: Get OpenFileDialog filename path...

      On Jun 27, 8:40 pm, parez <psaw...@gmail. comwrote:
      On Jun 27, 10:31 pm, SpreadTooThin <bjobrie...@gma il.comwrote:
      >
      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.GetDirecto ryName to get the path(directory)
      and you can use Path.VolumeSepa ratorChar to split the filename and use
      the first part. There could be better way of doing this.
      Path.GetDirecto ryName?
      I don't know where Path is what class is that?
      ..

      Comment

      • parez

        #4
        Re: Get OpenFileDialog filename path...

        On Jun 27, 10:46 pm, SpreadTooThin <bjobrie...@gma il.comwrote:
        On Jun 27, 8:40 pm, parez <psaw...@gmail. comwrote:
        >
        On Jun 27, 10:31 pm, SpreadTooThin <bjobrie...@gma il.comwrote:
        >
        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.GetDirecto ryName to get the path(directory)
        and you can use Path.VolumeSepa ratorChar to split the filename and use
        the first part. There could be better way of doing this.
        >
        Path.GetDirecto ryName?
        I don't know where Path is what class is that?
        ..
        System.IO

        Comment

        • Duggi

          #5
          Re: Get OpenFileDialog filename path...

          On Jun 28, 7:31 am, SpreadTooThin <bjobrie...@gma il.comwrote:
          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.InitialDir ectory = @"c:\";
          fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
          fdlg.FilterInde x = 2;
          fdlg.RestoreDir ectory = true;
          if (fdlg.ShowDialo g() == DialogResult.OK )
          {
          string dirName =
          System.IO.Path. GetDirectoryNam e(fdlg.FileName );
          string drive =
          dirName.Split(S ystem.IO.Path.V olumeSeparatorC har)[0];
          MessageBox.Show (dirName);
          MessageBox.Show (drive);
          }

          Hopefully this should help...

          Comment

          • SpreadTooThin

            #6
            Re: Get OpenFileDialog filename path...

            On Jun 28, 12:12 pm, Duggi <DuggiSrinivasa ...@gmail.comwr ote:
            On Jun 28, 7:31 am, SpreadTooThin <bjobrie...@gma il.comwrote:
            >
            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.InitialDir ectory = @"c:\";
                        fdlg.Filter = "All files (*.*)|*.*|All files (*..*)|*.*";
                        fdlg.FilterInde x = 2;
                        fdlg.RestoreDir ectory = true;
                        if (fdlg.ShowDialo g() == DialogResult.OK )
                        {
                            string dirName =
            System.IO.Path. GetDirectoryNam e(fdlg.FileName );
                            string drive =
            dirName.Split(S ystem.IO.Path.V olumeSeparatorC har)[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.

            Comment

            • Duggi

              #7
              Re: Get OpenFileDialog filename path...

              On Jun 29, 4:52 am, SpreadTooThin <bjobrie...@gma il.comwrote:
              On Jun 28, 12:12 pm, Duggi <DuggiSrinivasa ...@gmail.comwr ote:
              >
              >
              >
              On Jun 28, 7:31 am, SpreadTooThin <bjobrie...@gma il.comwrote:
              >
              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.InitialDir ectory = @"c:\";
              fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
              fdlg.FilterInde x = 2;
              fdlg.RestoreDir ectory = true;
              if (fdlg.ShowDialo g() == DialogResult.OK )
              {
              string dirName =
              System.IO.Path. GetDirectoryNam e(fdlg.FileName );
              string drive =
              dirName.Split(S ystem.IO.Path.V olumeSeparatorC har)[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

              Comment

              Working...