[C#] 纯文本查看 复制代码
/// <summary
/// 卸载
/// </summary>
/// <param name="savedState"></param>
public override void Uninstall(IDictionary savedState)
{
DeleteWebSite(); //删除安装文件前先删除站点,因删除站点时需读取安装文件的配置信息 dbpath = Path.Combine(this.Context.Parameters["installdir"].ToString(), "dbconfig.xml"); string connectionString = OperateXML.GetXmlNodeValue(dbpath, "ConnString"); string dbName = OperateXML.GetXmlNodeValue(dbpath, "DbName"); base.Uninstall(savedState); try
{ using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open(); string sql = "if exists(select 1 from master..sysdatabases where name= '" + dbName + "') drop database " + dbName;
ExecuteSQL(connection, sql);
connection.Close();
} if (Directory.Exists(Context.Parameters["installdir"].ToString() + "Message"))
{
Directory.Delete(Context.Parameters["installdir"].ToString() + "Message", true);//删除解压产生的文件
} if (Directory.Exists(Context.Parameters["installdir"].ToString() + "MoreUpload"))
{
Directory.Delete(Context.Parameters["installdir"].ToString() + "MoreUpload", true);
}
} catch (Exception ex)
{
MessageBox.Show("卸载失败!\n" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Rollback(savedState); return;
}
}