路径不合法形式错误openfiledialog

时间:2013-10-30 01:38:50

标签: c#

我解密文件时遇到错误。 “这条道路不是合法的形式”

如果我手动指向privateKeyLocation,例如string privateKeyLocation = @“c:\ privatekey.txt”,没关系,运行正常。

但我希望自己使用打开的文件对话框找到密钥文件。 谁知道出了什么问题? 提前谢谢!

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);
        }

1 个答案:

答案 0 :(得分:2)

只是简单的showdialog()及其结果:

        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);
            }
        }
相关问题