/// 向指定路徑寫入文件
/// </summary>
/// <param name="LogPath"></param>
public void WriteTestFlagFile(string LogPath)
{
try
{
if (!(File.Exists(LogPath)))
{//如果這個文件不存在,就創建這個文件
FileStream aFile = new FileStream(LogPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
StreamWriter sw = new StreamWriter(aFile);
sw.WriteLine("TestCompleteFlag");
sw.Close(); //釋放文件
aFile.Close();
sw.Dispose(); //釋放資源
aFile.Dispose();
}
}
catch (Exception)
{//寫入文件異常,這個地方一般是由於使用了非超級管理員權限向C盤寫入了文件,報告權限不夠
if (MessageBox.Show("Run me in the role of the super administrator!", "Information Tip:", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == DialogResult.OK)
{
this.Dispose();
Application.Exit();
}
}
}