我想实现这样一个功能:
我在一个textbox中显示一个路径的名称:假设是c:\myname\
我想在我不手动改变它的情况下,每次启动程序时,都是显示这个路径。
如果某一次启动后,我改成d:\yours\,那从这次后的每次启动都显示d:\yours\
请问:不通过读写数据库,能实现这样的功能吗?如果能该如何实现?
我在一个textbox中显示一个路径的名称:假设是c:\myname\
我想在我不手动改变它的情况下,每次启动程序时,都是显示这个路径。
如果某一次启动后,我改成d:\yours\,那从这次后的每次启动都显示d:\yours\
请问:不通过读写数据库,能实现这样的功能吗?如果能该如何实现?
解决方案 »
- C# 帮助文档 msdn帮助文档
- 请问下各位兄弟,SQL2005里面什么类型可以存储很多个字符串啊
- 正则表达式问题!把代码给我写出来(给50分)在写点注释解释一下80分全送
- 简单加法问题,两个操作数怎么相加?
- C#调用存储过程中返回的游标怎么读取和保存到变量中
- 多线程问题,怎么能让所有线程执行完后再执行之后的语句?急,在线等
- 在.net下开发ActiveX控件
- SubFabric.SetDataSource(ds2); 未将对象引用设置到对象的实例。
- 数据集DataSet中的表DataTable是数据库意义的表吗?能对数据集中的表进行关系运算吗?
- 请问我怎么在窗体启动时隐藏窗体 只显示 NotifyIcon图标
- CodeDom中怎么构造析构函数?
- webservice 定义的方法如何增加中文提示?
再用OpenFileDialog.RestoreDirectory属性设置关闭的时候是否还原目录就行了把OpenFileDialog的路径存入textbox.text里就可以了
如果不放数据库,那只有存放到文件中.代码非常简单读写文件:public ReadFile(string strFileName)
{
StreamReader sr = new StreamReader(strFileName),System.Text.Encoding.Default);
while (sr.Peek() >= 0)
{
Console.WriteLine(sr.ReadLine());
}
sr.Close();
}Public Shared Sub WriteFile(ByVal strLog As String, ByVal page As System.Web.UI.Page)
If Directory.Exists(page.Server.MapPath("LogFolder")) = False Then
Directory.CreateDirectory(page.Server.MapPath("LogFolder"))
End If
Dim pw As StreamWriter = New StreamWriter(page.Server.MapPath(".") & "\LogFolder\log.txt", True, System.Text.Encoding.UTF8)
pw.WriteLine(strLog)
pw.Flush()
pw.Close()
End Sub
txt,ini,xml 文件等等。
//读
public static string GetValue(string AppKey)
{
try
{
string AppKeyValue;
AppKeyValue=System.Configuration.ConfigurationSettings.AppSettings.Get(AppKey);
return AppKeyValue;
}
catch(Exception ex)
{
throw ex;
}
}
//写
public static void SetValue(string AppKey,string AppValue)
{
//System.Configuration.ConfigurationSettings.AppSettings.Set(AppKey,AppValue);
XMLDocument xDoc = new XmlDocument();
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config"); XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings"); xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key=''" + AppKey + "'']");
if ( xElem1 != null ) xElem1.SetAttribute("value",AppValue);
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key",AppKey);
xElem2.SetAttribute("value",AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
}
读取:TextBox2.Text=System.Configuration.ConfigurationSettings.AppSettings["FilePath"]
修改:
if(System.Configuration.ConfigurationSettings.AppSettings["FilePath"]==TextBox2.Text)
return;
//打开配置文件)
//string filename =System.Windows.Forms.Application.ExecutablePath + ".config";//此为winform程序配置文件路径
string filename =Server.MapPath(@"web.config");//此为webform程序配置文件路径
XmlDocument xmldoc= new XmlDocument();
xmldoc.Load(filename);
XmlNodeList xNodes=xmldoc.DocumentElement.ChildNodes;
foreach(XmlElement xe in xNodes)
{
if(xe.Name.ToLower()=="appsettings")
if(xe.ChildNodes.Count>0)
foreach(XmlElement cxe in xe.ChildNodes)
if(cxe.Attributes["key"].InnerText=="FilePath")
cxe.Attributes["value"].Value =TextBox2.Text;
}
xmldoc.Save(filename);