读写INI文件
打开页面可读取INI文件里的相应数据,但修改数据后点确定不会写进INI文件。高手帮忙看看。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="attconfig.aspx.cs" Inherits="_Default111a" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
<link href="CssV3/Web_left.css" rel="stylesheet" type="text/css" />
<link href="style/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
background-color: #c4d8ed;
}
.STYLE6 {color: #000000;
font-weight: bold;
}
.STYLE7 {color: #135294}
.STYLE8 {
color: #FF0000;
font-weight: bold;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body>
<form id="form1" runat="server">
<div>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#284885">
<tr>
<td width="20%" colspan="2" align="left" valign="middle" bgcolor="#E4EDF9"><span style="width: 186px"> </span><span class="td2"><span class="STYLE6"> </span></span> <br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="C4D8ED">
<tr>
<td height="28" bgcolor="#F1F3F5"><span class="STYLE7"> [设置] </span></td>
</tr>
</table>
<br /><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="C4D8ED">
<tr>
<td colspan="2" align="left" bgcolor="F1F3F5" style="height: 26px"> </td>
</tr>
<tr>
<td width="32%" height="30" align="right" bgcolor="F1F3F5" style="height: 26px">
A帐号:</td>
<td width="68%" height="26" align="left" bgcolor="F1F3F5" style="height: 26px">
<asp:TextBox CssClass="td1" ID="userid" runat="server" Width="243px"></asp:TextBox>
</td>
</tr>
<tr>
<td width="32%" height="30" align="right" bgcolor="F1F3F5" style="height: 26px">
B比例:</td>
<td width="68%" height="26" align="left" bgcolor="F1F3F5" style="height: 26px">
<asp:TextBox CssClass="td1" ID="userid1" runat="server" Width="243px"></asp:TextBox>
</td>
</tr>
<tr>
<td height="30" align="right" bgcolor="F1F3F5">
确认修改:</td>
<td height="26" align="left" bgcolor="F1F3F5">
<asp:Button CssClass="bt2" ID="Button1" runat="server" Text="提交" Width="134px" OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td height="83" colspan="2" align="center" bgcolor="F1F3F5"><table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="32%" height="69"> </td>
<td width="68%" align="left"><span class="STYLE8">注意:<br>
内容 </span></td>
</tr>
</table>
<br /></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="top" bgcolor="#F1F3F5"> </td>
<td valign="top" bgcolor="#F1F3F5"> </td>
</tr>
</table></td>
</tr>
</table>
<br />
<br />
</div></form>
</body>
</html>
cs文件:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default111a : System.Web.UI.Page
{
private static string inipath = ConfigurationManager.ConnectionStrings["inipath"].ConnectionString; //读取数据库连接串
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
INIFILE ini = new INIFILE();
ini.FilePath = inipath + "AConfig.ini";
string strReturnValue = ini.ReadValue("public", "USERID");
this.userid.Text = strReturnValue;
string strReturnValue1 = ini.ReadValue("public", "CHUPER");
this.userid1.Text = strReturnValue1;
}
//Write
// Response.Write(strReturnValue);
}
protected void Button1_Click(object sender, EventArgs e)
{
INIFILE ini = new INIFILE();
ini.FilePath = inipath + "AConfig.ini";
string wstr = this.userid.Text.ToString().Trim();
// Response.Write(wstr);
ini.WriteValue("public", "USERID", wstr);
string wstr1 = this.userid1.Text.ToString().Trim();
// Response.Write(wstr);
ini.WriteValue("public", "CHUPER", wstr1);
string okd = common.alert("操作成功!");
Response.Write(okd);
[解决办法]
看看是否有写的权限。