2017-10-26 27 views
0

非常に新しい#になってしまい、ファイルに書き込もうとしていますが、このエラーが発生します。助言がありますか?ファイルに書き込むときにunauthorisedAccessExceptionが発生する

System.UnauthorizedAccessException: 'Access to the path 'C:\Users\tom\Desktop\theBeast\theBeast\bin\Debug' is denied.' 
my code: 

string hashedValue = Hash(hashed); 
string Path = @"\Users\tom\Desktop\theBeast\theBeast\bin\Debug"; 

using (System.IO.StreamWriter Account = new System.IO.StreamWriter(Path, true)) 
{ 
    Account.WriteLine(Username + "," + hashedValue + ",User"); 
    System.Windows.Forms.MessageBox.Show("Account Successfully Created"); 
} 
+0

あなたのコードを投稿することをお勧めします。 –

+0

そのディレクトリに書き込む権限がありますか?新しいファイルを作成しようとすると、あなたが拒否されたとか、管理者権限が必要だと言われますか? – astidham2003

+3

Path変数にフォルダではなくファイルへのパスが含まれていると思います。 @ "... \ Debug \ filename.txt" – Artem

答えて

0

何かを書き込むためにファイルパスを使用し、ファイルを保存するにはストリームを閉じる必要があります。 あなたはこれを試してください:

string hashedValue = Hash(hashed); 
string Path = @"\Users\tom\Desktop\theBeast\theBeast\bin\Debug\test.txt"; 

using (System.IO.StreamWriter Account = new System.IO.StreamWriter(Path , true)) 
      { 
       Account.WriteLine(Username + "," + hashedValue + ",User"); 
       Account.Close(); 
       System.Windows.Forms.MessageBox.Show("Account Successfully Created"); 
      } 
関連する問題