2013-10-30 17 views
0

我解密我的文件時出現錯誤。 「路徑不是合法形式」路徑不合法的形式錯誤openfiledialog

如果我手動指定privateKeyLocation,例如字符串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

什麼是一個值的例子'privateKeyLocation'你'的FileInfo()的ToString()'進去呢?另外,「打開」對話框是否正確顯示?你需要調用'openFileDialog1.ShowDialog()'? – cxw

回答

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); 
      } 
     } 
相關問題