vs 2005中类库如何访问 app.config


  #region 取得Lib的App.config的连接字符串


  try


  {


  string fileFullPath = Assembly.GetExecutingAssembly().CodeBase.Replace("[url=file:///]file:///", string.Empty);


  string filePath = fileFullPath.Substring(0, fileFullPath.LastIndexOf("/")) + "/App.config";


  if (document == null)


  {


  document = new XmlDocument();


  }


  document.Load(filePath);


  connectionString = document.SelectSingleNode(@"/configuration/appSettings/add[@key='connString']").Attributes["value"].Value;


  }


  catch (XmlException ex)


  {


  throw new XmlException(ex.Message);


  }


  #endregion

posted @ 2011-01-12 22:23  likunran  阅读(120)  评论(0编辑  收藏  举报