private void openFileDialog_FileOk(object sender, CancelEventArgs e) { //don't check larger files if (new FileInfo(openFileDialog.FileName).Length > 4 * 4 * 1024 || !PrivateKeyFile.IsValid(openFileDialog.FileName)) { MessageBox.Show(this, "File doesn't seem to be a valid private key file", Text); e.Cancel = true; } }