app.config پیغام خطا هنگام اجرا
سلام توسط کدهای زیر می توانم در RunTime فایل app.config را تغییر بدهم
private void picOk_Click(object sender, EventArgs e)
{
try
{
//information for connection
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(AppDomain.CurrentDomain.BaseDirectory + @"..\..\App.config");
XmlNode appsetting = xmldoc.SelectSingleNode("configuration/connectionStrings");
foreach (XmlNode ChildNode in appsetting)
{
if (ChildNode.Attributes["name"].Value == "mydatabasename")
ChildNode.Attributes["connectionString"].Value = "Server=" + txtServer.Text + ";DataBase=" + txtDataBase.Text + ";User=" + txtUser.Text + ";Pwd=" + txtPasswordUser.Text;
if (ChildNode.Attributes["name"].Value == "Server")
ChildNode.Attributes["connectionString"].Value = txtServer.Text;
if (ChildNode.Attributes["name"].Value == "DataBase")
ChildNode.Attributes["connectionString"].Value = txtDataBase.Text;//name data base
if (ChildNode.Attributes["name"].Value == "User")
ChildNode.Attributes["connectionString"].Value = txtUser.Text;//name user id
if (ChildNode.Attributes["name"].Value == "Pwd")
ChildNode.Attributes["connectionString"].Value = txtPasswordUser.Text;//password bank
}
xmldoc.Save(AppDomain.CurrentDomain.BaseDirectory + @"..\..\App.config");
xmldoc.Save(AppDomain.CurrentDomain.SetupInformati on.ConfigurationFile);
//change conect
{
getconnectionstrings();
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);
config.AppSettings.Settings.Add("NewConnectionStri ng",Connect + " ");
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("connectionStr ings");
}
progressBar1.Maximum = 1000000;
progressBar1.Visible = true;
for (int j = 0; j < 1000000; j++)
progressBar1.Value += 1;
progressBar1.Visible = false;
i = 0;
this.Size = new Size(494, 216);//min
txtName.Focus();
}
catch (XmlException ml)
{
MessageBox.Show(ml.Message);
}
}
حالا توسط خود ویژوال یک SetUp برای برنامه ام ساخته ام ولی هنگام اجرا پیغام می دهد که نمی تواند فایل App.config را "c:\programfile\cmr\app.config" پیدا کنه چه کار باید کرد ?
نقل قول: app.config پیغام خطا هنگام اجرا
من فکر میکنم شما اشتباها یک فایل موقتی کانفیگ رو به پروژه اد میکنید.فایل اصلی کنار اسمبلی برنامه قرار میگیره. که اون رو باید تو ستاپ سازی اد کنید.
توی این لینک توضیحاتی راجع به تفاوت این دو فایل هست.
http://www.barnamenevis.org/sh...d.php?t=171661
امیدوارم بدردتون بخوره.