Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save alws34/ed58350a4945f3f5edae9da6f1609de0 to your computer and use it in GitHub Desktop.

Select an option

Save alws34/ed58350a4945f3f5edae9da6f1609de0 to your computer and use it in GitHub Desktop.
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog fbd = new OpenFileDialog() {
ValidateNames = false,
CheckFileExists = false,
CheckPathExists = true,
FileName = "Folder Selection."
};
if (fbd.ShowDialog() == DialogResult.OK)
textBoxPath.Text = Path.GetDirectoryName(fbd.FileName);
}
@alws34
Copy link
Author

alws34 commented Jan 13, 2023

Get full file path

public static string GetFilePath()
{
    OpenFileDialog openFileDialog = new OpenFileDialog();
    openFileDialog.InitialDirectory = "c:\\";
    openFileDialog.Filter = "All files (*.*)|*.*";
    openFileDialog.FilterIndex = 1;
    openFileDialog.RestoreDirectory = true;

    if (openFileDialog.ShowDialog() == DialogResult.OK)
        return openFileDialog.FileName;
    return null;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment