我正在做一個小小的備份工具......而且我有一個小問題,不知道如何解決這個問題。所以這就是爲什麼我問這裏...代碼:該進程無法訪問該文件,因爲它正在被另一個進程使用#2
strDirectoryData = dlg1.SelectedPath;
strCheckBoxData = "true";
clsCrypto aes = new clsCrypto();
aes.IV = "MyIV"; // your IV
aes.KEY = "MyKey"; // your KEY
strDirectoryEncryptedData = aes.Encrypt(strDirectoryData, CipherMode.CBC);
strCheckBoxEncryptedData = aes.Encrypt(strCheckBoxData, CipherMode.CBC);
StreamWriter dirBackup = new StreamWriter(dirBackupPath, false, Encoding.UTF8);
StreamWriter checkBackup = new StreamWriter(autoBackupPath, false, Encoding.UTF8);
dirBackup.WriteLine(strDirectoryEncryptedData, Encoding.UTF8);
dirBackup.Close();
checkBackup.WriteLine(strCheckBoxData, Encoding.UTF8);
checkBackup.Close();'
得到一個錯誤每次 - 因爲它正由另一個進程的進程無法訪問該文件...
我也有這在Form1_Load
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
string strCheckBoxData;
string strDirectoryData;
string strCheckBoxEncryptedData;
string strDirectoryEncryptedData;
strDirectoryData = "Nothing here";
strCheckBoxData = "false";
clsCrypto aes = new clsCrypto();
aes.IV = "MyIV"; // your IV
aes.KEY = "MyKey"; // your KEY
strDirectoryEncryptedData = aes.Encrypt(strDirectoryData, CipherMode.CBC);
strCheckBoxEncryptedData = aes.Encrypt(strCheckBoxData, CipherMode.CBC);
StreamWriter dirBackup = new StreamWriter(dirBackupPath, false, Encoding.UTF8);
StreamWriter checkBackup = new StreamWriter(autoBackupPath, false, Encoding.UTF8);
dirBackup.WriteLine(strDirectoryEncryptedData);
dirBackup.Close();
checkBackup.WriteLine(strCheckBoxEncryptedData);
checkBackup.Close();
}
else
{
string strCheckBoxDecryptedData;
string strDirectoryDecryptedData;
StreamReader dirEncrypted = new StreamReader(dirBackupPath);
StreamReader checkEncrypted = new StreamReader(autoBackupPath);
任何想法?
請停止使用匈牙利命名法。這是一個建議:) – miniBill