Reputation: 69
I am getting a error when i decrypt my file. "The path is not of a legal form"
if i direct the privateKeyLocation manually e.g. string privateKeyLocation = @"c:\privatekey.txt", its okay and runs fine.
But i want to find the key file myself using open file dialog. Anybody know what went wrong? Thanks in advance!
private void decryptFileButton_Click(object sender, EventArgs e)
{
string inputFileLocation = attachmentTextBox.Text;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.RestoreDirectory = true;
string privateKeyLocation = new FileInfo(openFileDialog1.FileName).ToString();
string privateKeyPassword = passphrase2TextBox.Text;
string outputFile = @"c:\Original.txt";
// decrypt and obtain the original file name
// of the decrypted file
string originalFileName =
pgp.DecryptFile(inputFileLocation,
privateKeyLocation,
privateKeyPassword,
outputFile);
}
Upvotes: 0
Views: 311
Reputation: 4542
Just a simple matter of showdialog() and its result:
private void decryptFileButton_Click(object sender, EventArgs e)
{
string inputFileLocation = attachmentTextBox.Text;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string privateKeyLocation = new FileInfo(openFileDialog1.FileName).ToString();
string privateKeyPassword = passphrase2TextBox.Text;
string outputFile = @"c:\Original.txt";
decrypt and obtain the original file name
of the decrypted file
string originalFileName =
pgp.DecryptFile(inputFileLocation,
privateKeyLocation,
privateKeyPassword,
outputFile);
}
}
Upvotes: 2