读写xml文件并保存到我选择的系统文件夹之一中 [英] read and write the xml files and saved in to one of my selected system folder

查看:70
本文介绍了读写xml文件并保存到我选择的系统文件夹之一中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨........
任何人都可以帮助我

我写了这样的代码

但它拒绝出现错误,例如访问路径" C:\ Documents and Settings \ kiran \ Desktop \ sample.xml"."

Hi........
Any one please help to me

i wrote code like this

but its coming error like "Access to the path ''C:\Documents and Settings\kiran\Desktop\sample.xml'' is denied."

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

public partial class xmlExample : System.Web.UI.Page
{
    XmlTextWriter xw;
    string FName;
    protected void Page_Load(object sender, EventArgs e)
    {
        FName = "C:\\Documents and Settings\\kiran\\Desktop\\sample.xml";
        xw = new XmlTextWriter(FName, System.Text.Encoding.UTF8);
        xw.WriteStartDocument();
        xw.WriteStartElement("Employee");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        xw.WriteStartElement("EmployeeDetails");
        xw.WriteStartElement("Empid");
        xw.WriteValue(TextBox1.Text);
        xw.WriteEndElement();
        xw.WriteStartElement("Ename");
        xw.WriteValue(TextBox2.Text);
        xw.WriteEndElement();
        xw.WriteStartElement("Email Id");
        xw.WriteValue(TextBox3.Text);
        xw.WriteEndElement();
        xw.WriteEndElement();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        xw.WriteEndElement();
        xw.WriteEndDocument();
        xw.Close();
    }
}



您能帮我吗,但是它可以在Windows窗体中正常工作,而不能在Web窗体中正常工作,请修改代码并发送清晰的结果,此过程错误意味着发送方法 读取和写入xml文件并保存到我选择的系统文件夹之一中



can u please help me but its working fine in windows form,and not working in web forms modify the code and send clear result please,this process wrong means send how to do
read and write the xml files and saved in to one of my selected system folder

推荐答案

1.检查您的文件处于只读模式.如果是,请取消选中文件属性中的只读选项.

2.如果通过IIS运行,则必须授予iisusrs对该文件夹的权限.

转到您拥有xml的文件夹,然后单击属性"->安全"标签->编辑">添加".

位置->选择您的计算机名称
输入要选择的对象,然后输入iis_iusrs.
单击确定.
然后选中完全控制-允许"复选框

保存它.现在,iis用户将有权在该文件夹中写入任何文件
1. Check your file is in read only mode. If yes, uncheck the readonly options in the properties of the file.

2. If you are running through IIS, u have to give permission to iisusrs to that folder.

Go to the folder where you have your xml and click on properties->Security tab->Edit>Add.

Location->select ur machine name
Enter the object u neeed to select , enter iis_iusrs.
Click on ok.
Then select Full control-Allow checkbox

Save it.Now iis users will have permission to write any files inside that folder


这与您的代码本身无关.访问被拒绝. ASP.NET无法访问此目录.您只能使用网站根目录下的文件.要获取与站点的虚拟路径相对应的物理文件系统对象的正确路径,请使用System.Web.HttpServerUtility.MapPath:
http://msdn.microsoft.com/en-us/library/system. web.httpserverutility.mappath.aspx [ ^ ].

同样,像您一样使用XML也不是一个错误,但是这几乎没有道理.在大多数情况下,您可以使用序列化,尤其是 Data Contract ,这是持久保存任何对象或对象图的最健壮,不引人注目且易于使用的方式:
http://msdn.microsoft.com/en-us/library/ms973893.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

—SA
This is not related to your code per se. Access is denied. This directory is not accessible by ASP.NET. You can only work with files under the root directory of your site. To get a correct path to a physical file system object corresponding to a site''s virtual path, use System.Web.HttpServerUtility.MapPath:
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx[^].

Also, working with XML like you do is not a mistake, but it rarely makes sense. In most cases, you can use serialization, in particular, Data Contract, which is the most robust, unobtrusive and easy to use way to persist any object or object graph:
http://msdn.microsoft.com/en-us/library/ms973893.aspx[^],
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

—SA


asp.net功能为该功能提供了虚拟路径和物理路径检查,它将助您一臂之力
asp.net fuctinality provides virtual path and physical path check for that fuction it will hep you out


这篇关于读写xml文件并保存到我选择的系统文件夹之一中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆