1:读取过程
public void ApplyConnectionInfo() {
string strConnection = string.Empty;
doc.Load(this.openFileName);
foreach (XmlNode node in doc["configuration"]["connectionStrings"].ChildNodes) {
if (node.Name == "add") {
if (node.Attributes["name"].Value == "connectionString") {
strConnection = node.Attributes["connectionString"].Value;
}
}
}
string[] ConnInfo = strConnection.Split(';');
for (int i = 0; i < ConnInfo.Length; i++) {
string strTemp = ConnInfo[i].Trim();
if (strTemp.Length == 0) continue;
string Perfix = strTemp.Substring(0, strTemp.IndexOf("="));
if(Perfix.ToUpper().Equals("SERVER")) this.serverName = strTemp.Substring(strTemp.IndexOf("=") + 1);
if (Perfix.ToUpper().Equals("DATABASE")) this.database = strTemp.Substring(strTemp.IndexOf("=") + 1);
if (Perfix.ToUpper().Equals("UID")) this.userName = strTemp.Substring(strTemp.IndexOf("=") + 1);
if (Perfix.ToUpper().Equals("PWD")) this.password = strTemp.Substring(strTemp.IndexOf("=") + 1);
}
foreach (XmlNode node in doc["configuration"]["appParams"].ChildNodes) {
if (node.Name == "add") {
if (node.Attributes["key"].Value == "remoteHostString") {
this.remoteIP = node.Attributes["value"].Value;
}
}
}
foreach (XmlNode node in doc["configuration"]["system.web"].ChildNodes) {
if (node.Name == "identity") {
this.SNuserName = node.Attributes["userName"].Value;
this.SNpassword = node.Attributes["password"].Value;
}
}
}
2:修改并保存
public void SaveConnectionInfo() {
try {
string strConnectionstring = String.Format("Server={0};Database={1};uid={2};pwd={3}", this.ServerName, this.DataBaseName, this.UserID, this.UserPassword);
doc.Load(this.OpenPath);
foreach (XmlNode node in doc["configuration"]["connectionStrings"].ChildNodes) {
if (node.Name == "add") {
if (node.Attributes["name"].Value == "connectionString") {
node.Attributes["connectionString"].Value = strConnectionstring;
}
}
}
foreach (XmlNode node in doc["configuration"]["appParams"].ChildNodes) {
if (node.Name == "add") {
if (node.Attributes["key"].Value == "remoteHostString") {
node.Attributes["value"].Value = this.RemoteIP;
}
if (node.Attributes["key"].Value == "connectionString") {
node.Attributes["value"].Value = strConnectionstring;
}
}
}
foreach (XmlNode node in doc["configuration"]["system.web"].ChildNodes) {
if (node.Name == "identity") {
node.Attributes["userName"].Value=this.SNuserName ;
node.Attributes["password"].Value=this.SNpassword ;
}
}
System.IO.File.SetAttributes(this.openFileName, System.IO.FileAttributes.Normal);
doc.Save(this.openFileName);
System.IO.File.SetAttributes(this.openFileName, System.IO.FileAttributes.ReadOnly);
MessageBox.Show("PMFE web confirg file setting is saved!");
} catch (Exception e) {
MessageBox.Show("Error,Save is faile!");
}
}
3:'Web.confirg文件
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="uipConfiguration" type="Microsoft.ApplicationBlocks.UIProcess.UIPConfigHandler,Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null" />
<section name="appParams" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<uipConfiguration enableStateCache="true" allowBackButton="false">
<objectTypes>
<iViewManager name="WebFormViewManager" type="Microsoft.ApplicationBlocks.UIProcess.WebFormViewManager, Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null" default="true" />
<state name="State" type="Microsoft.ApplicationBlocks.UIProcess.State, Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null" default="true" />
<controller name="WelcomeController" type="PMFE.UI.Component.Common.WelcomeController,PMFE.UI.Component, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" />
<statePersistenceProvider name="MemoryPersistState" type="Microsoft.ApplicationBlocks.UIProcess.MemoryStatePersistence, Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null" connectionString="server=.;database=UIPState;uid=rpms;pwd=rpms" default="true" />
</objectTypes>
<views>
<view name="WELCOME" type="Welcome.aspx" controller="WelcomeController" />
</views>
</uipConfiguration>
<system.web>
<identity impersonate="true" userName="Angel Wong" password="axio55" />
<compilation defaultLanguage="c#" debug="true">
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Infragistics2.WebUI.Shared.v5.3, Version=5.3.20053.73, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" />
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.ReportSource, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.Shared, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="Infragistics2.WebUI.UltraWebGrid.ExcelExport.v5.3, Version=5.3.20053.73, Culture=neutral, PublicKeyToken=7DD5C3163F2CD0CB" />
<add assembly="Infragistics2.Excel.v5.3, Version=5.3.20053.73, Culture=neutral, PublicKeyToken=7DD5C3163F2CD0CB" />
</assemblies>
<compilers>
<compiler language="c#" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" extension=".cs" compilerOptions="/d:DEBUG;TRACE" />
</compilers>
</compilation>
<customErrors mode="RemoteOnly" />
<authentication mode="None" />
<!--<identity impersonate="true" userName="*" password="*" />-->
<!--<authorization>
<deny users="?" />
</authorization>-->
<trace enabled="false" requestLimit="10" pageOutput="true" traceMode="SortByTime" localOnly="true" />
<sessionState mode="InProc" cookieless="false" timeout="10" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
<xhtmlConformance mode="Legacy" />
<pages />
</system.web>
<appParams>
<add key="connectionString" value="Server=Server06;Database=PMFE;uid=*;pwd=*" />
<add key="remoteHostString" value="192.168.170.99" />
</appParams>
<connectionStrings>
<add name="connectionString" connectionString="Server=Server06;Database=PMFE;uid=*;pwd=*" providerName="System.Data.SqlClient" />
</connectionStrings>
<location path="en">
<system.web>
<globalization culture="en" uiCulture="en" />
</system.web>
</location>
</configuration>
分享到:
相关推荐
NULL 博文链接:https://sunyf.iteye.com/blog/1718380
本超简洁HTML在线编辑器(.NET C#)IE 是程序源代码,只需将其复制到应用程序根目录下(和Web.config在同一目录),然后再需要的地方引入WebEditor.ascx控件即可使用。通过其Value属性或SetValue()、GetValue()读取和...
通过读取config.ini配置访问数据库 仿QQ登录下拉框 头像 详细下载后看源码
1.4.1 Web.Config文件设计 11 1.4.2 操作XML连接路径类 12 1.5 论坛版面设计与管理 13 1.5.1 论坛版面管理 13 1.5.2 创建论坛版面 16 1.5.3 编辑论坛版面 18 1.6 论坛帖子设计与管理 20 1.6.1 发布...
Visual Web Development 2005开发ASP.NET使用小技巧 ASP.NET 2.0 异步页面原理浅析 [1] [原] 自定义通用System.Web.UI.IHierarchicalDataSource简单实现 在 ASP.NET 2.0 中创建 Web 应用程序主题 ASP.NET 2.0 中的...
因pdf的容量过大分4个压缩包打包,还有一个源码另外下载。 《.NET深入体验与实战精要》作者身为从事.NET一线开发的资深开发专家,常年耕耘技术博客,惠及无数.NET新知。此次将长期的思考、感悟,多年的系统开发、...
因pdf的容量过大分4个压缩包打包,还有一个源码另外下载。 《.NET深入体验与实战精要》作者身为从事.NET一线开发的资深开发专家,常年耕耘技术博客,惠及无数.NET新知。此次将长期的思考、感悟,多年的系统开发、...
简单C#信息采集工具实现 http://blog.csdn.net/xiaoxiao108/archive/2011/06/01/6458367.aspx 最近想整只爬虫玩玩,顺便熟悉下正则表达式。 开发环境 vs2008 sql2000 实现方法如下 1.先抓取网页代码 2.通过正则...
C# 读取保存App.config配置文件的完整源码参考(转) http://smartsoft.5d6d.com/thread-6550-1-1.html C# 读取保存App.config配置文件的完整源码参考 最近出差在北京做一个小项目,项目里需要读取配置文件的小功能...
23..net Remoting 的工作原理是什么? 答:服务器端向客户端发送一个进程编号,一个程序域编号,以确定对象的位置。 24.在C#中,string str = null 与 string str = “” 请尽量使用文字或图象说明其中的区别。 ...
此程序名称为 Autoupdate.exe 此外此程序是读取在程序根目录下的server文件夹下面的同时他还附带了一个名为:app.config的配置文件。其中IsDownLoad 是判断运行状态的 当是1时候直接会下载更新的数据,客户端电脑...
如今搞任何一个项目,数据显示都应在网格中显示,一个封装好的网格自定义控件是每个项目...此程序分别 “Dev自定义网格控件”和 "微软自带自定义网格控件",都已封边完毕,支持分页、自动读取Config配置文件加载列数据
C#编程经验技巧宝典源代码,目录如下: 第1章 开发环境 1 <br>1.1 Visual Studio开发环境安装与配置 2 <br>0001 安装Visual Studio 2005开发环境须知 2 <br>0002 配置合适的Visual Studio 2005...
针对一个图像编辑器项目需求,利用 Visual Studio 集成开发环境,采用了OPenCvSharp技术、C#语言、文件读取、图像滤镜、形态学处理、边缘检测、访问像素、图像滤波、阈值分割、屏幕截图技术等,完成系统界面设计和...
配置生成器是.Net 4.7.1中引入的完整.Net Framework的新功能。 您可以在了解有关此概念的。 通过此项目,Microsoft提供了一组基本的配置生成器,这些配置生成器应使开发人员可以轻松地在其应用程序中利用此功能。 ...