使用 DataSet 从 XML文件 读取数据, 那我怎么保存更改...更新读取的XML文件

btbtd 2007-02-07 05:25:59

// 这里出错
dsDataSet.WriteXml(RootPath+"config.xml");

//---------------------------------------------------

public void EditInfo(Object s, EventArgs e)
{
String Username=System.Web.HttpContext.Current.Request.Form["Username"]+"";
String Password=System.Web.HttpContext.Current.Request.Form["Password"]+"";
//Password=md5(Password);
String CheckCode=System.Web.HttpContext.Current.Request.Form["CheckCode"]+"";
String CheckCodeSession=System.Web.HttpContext.Current.Session["GalleryCheckCode"]+"";

if(debug)
{
System.Web.HttpContext.Current.Response.Write("<li/>"+Username);
System.Web.HttpContext.Current.Response.Write("<li/>"+Password);
System.Web.HttpContext.Current.Response.Write("<li/>"+CheckCode);
System.Web.HttpContext.Current.Response.Write("<li/>"+CheckCodeSession);
System.Web.HttpContext.Current.Response.Write("<hr/>");
}

if(CheckCode!=CheckCodeSession)
{
Message("验证码错误!");
goto Error;
}

if(Username=="")
{
Message("用户名不能为空!");
goto Error;
}

Finished:;

RootPath=System.Web.HttpContext.Current.Server.MapPath(".");
if(!RootPath.EndsWith("\\"))RootPath+="\\";
DataSet dsDataSet=new DataSet();
DataTable dtConfig=new DataTable();

dsDataSet.ReadXml(RootPath+"config.xml");
dtConfig=dsDataSet.Tables["Config"];

dtConfig.Rows[0]["Username"]=Username;

if(Password!="")
{
dtConfig.Rows[0]["Password"]=md5(Password);
}

// 这里出错
dsDataSet.WriteXml(RootPath+"config.xml");

dsDataSet.Dispose();
dtConfig.Dispose();

Error:;

goto End;

End:;
}
...全文
274 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
btbtd 2007-02-07
  • 打赏
  • 举报
回复
幕白兄高...的确是权限问题...
无法删除二级目录的内容, 一级目录可以....
btbtd 2007-02-07
  • 打赏
  • 举报
回复
晕, 难道是 DataTable?
我捉一下虫子再说, 这个 XML 文件我有多个功能需要使用, 可以是某些进程忘记关了...
cpp2017 2007-02-07
  • 打赏
  • 举报
回复
ReadXml并不会占用xml文件
btbtd 2007-02-07
  • 打赏
  • 举报
回复
顶上去, 待一会再来看...
btbtd 2007-02-07
  • 打赏
  • 举报
回复
写入权限肯定是有的...

应该是这个:
dsDataSet.ReadXml(RootPath+"config.xml");
占据了文件的使用权, 因此写入不了,

不过 DataSet 又没有什么 Update的讲法...

该 怎么弄呀...
cpp2017 2007-02-07
  • 打赏
  • 举报
回复
是不是没有写入的权限?
btbtd 2007-02-07
  • 打赏
  • 举报
回复
错误信息N长, 应该是线程问题.....

Server Error in '/' Application.
Access to the path "G:\photo\gallery\config.xml" is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path "G:\photo\gallery\config.xml" is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[UnauthorizedAccessException: Access to the path "G:\photo\gallery\config.xml" is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) +888
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +45
System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding) +34
System.Data.DataSet.WriteXml(String fileName, XmlWriteMode mode) +48
System.Data.DataSet.WriteXml(String fileName) +7
Gallery.EditInfo(Object s, EventArgs e) +851
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277


Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧