Click here to Skip to main content
15,917,611 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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."
C#
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();
    }
}


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
Posted
Updated 8-Aug-12 6:06am
v2
Comments
barneyman 7-Aug-12 21:21pm    
access is denied

Does the IIS hosting user have ACL access that dir?
Sergey Alexandrovich Kryukov 7-Aug-12 21:23pm    
Why anyone should do your work? If you have a question, please ask it, but "send me" will hardly work here. Hire a developer instead.
--SA

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
 
Share this answer
 
Comments
Volynsky Alex 8-Aug-12 19:05pm    
+5!
Santhosh Kumar Jayaraman 9-Aug-12 1:06am    
thanks. but You didnt rate it:(
Volynsky Alex 9-Aug-12 3:54am    
Now it's ok...
Santhosh Kumar Jayaraman 9-Aug-12 4:33am    
thanks:)
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
 
Share this answer
 
v2
Comments
lokesh lokesh 7-Aug-12 23:01pm    
please send clear example its not working
lokesh lokesh 7-Aug-12 23:02pm    
please send clear example its not working
Sergey Alexandrovich Kryukov 8-Aug-12 0:10am    
You don't tell us what's "not working". This is not informative. A "clear example" is in the first reference article.
--SA
lokesh lokesh 8-Aug-12 2:36am    
again i changed like this

FName = Server.MapPath("~/XMLFile.xml");
xw = new XmlTextWriter(FName, System.Text.Encoding.UTF8);
xw.WriteStartDocument();
xw.WriteStartElement("Employee");

same error is coming please help me
Sergey Alexandrovich Kryukov 8-Aug-12 13:29pm    
Well, now check up the permissions for this physical directory...
--SA
asp.net fuctinality provides virtual path and physical path check for that fuction it will hep you out
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900