61,826
社区成员




public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
Form1 fr = new Form1();
if (fr.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
try
{
XmlDocument xmldocument = new XmlDocument();
xmldocument.Load(Path.Combine(getpath(), "Web.config"));
//'查找到appsettings中的节点
//XmlNode node=new XmlNode();
bool FoundIt = false;
XmlNodeList nodes = xmldocument.SelectSingleNode("/configuration/connectionStrings").ChildNodes;
foreach (XmlNode node in nodes)
{
if (node.Name == "add")
{
if (node.Attributes["name"].Value == "myconnString")
{
//'写入连接字符串
node.Attributes["connectionString"].Value = String.Format("Data Source={0};User ID={1};pwd={2};Initial Catalog={3}",
fr.DbServer, fr.LoginName, fr.Password, fr.Db);
FoundIt = true;
xmldocument.Save(Path.Combine(getpath(), "Web.config"));
}
}
}
if (!FoundIt)
{
throw new ApplicationException("Web.Config 文件没有包含connectionString连接字符串设置");
}
else
{
CreateVirtualDir(fr.SiteName, this.Context.Parameters[""]);
}
}
catch (Exception ex)
{
throw ex;
}
}
else
{
throw new ApplicationException("应用程序数据库安装失败");
}
}