CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2005
    Posts
    40

    The path of a file using openFileDialog

    I know it's quite a noob question but, how can I, using an openFileDialog, saving the path of the file in a string called etPath?
    This is my part of the code:

    Code:
    		public void etButtonBrowse_Click(object sender, System.EventArgs e)
    		{
    			etBrowseFileDialog.ShowDialog();
    			string etPath;
    			etPath = etBrowseFileDialog.FileName;
    		}
    I know that the last part (etPath = etBrowseFileDialog.FileName;) isn't correct.

    etButtonBrowse is the button which opens the FileDialog called "etBrowseFileDialog".

    Thanks!
    Last edited by StevDevil; November 12th, 2005 at 06:09 AM.

  2. #2
    Join Date
    May 2004
    Location
    Greenville, NC
    Posts
    193

    Re: The path of a file using openFileDialog

    Why doesn't this work?

    Code:
    using (OpenFileDialog ofd = new OpenFileDialog())
    {
        if (ofd.ShowDialog() == DialogResult.OK)
        {
            string etPath = ofd.FileName;
        }
    }
    Jason Isom
    .NET 2.0 / VS2005 Developer

  3. #3
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890

    Re: The path of a file using openFileDialog

    as Jason has mentioned so that way you can access, make sure you check for ok condition and then assign the filename.

    paresh
    - Software Architect

  4. #4
    Join Date
    Aug 2005
    Posts
    40

    Re: The path of a file using openFileDialog

    OK Thanks guys problem's solved!
    Last edited by StevDevil; November 13th, 2005 at 03:48 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured