Click here to Skip to main content
15,667,735 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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);
    protected void Button1_Click(object sender, EventArgs e)

        xw.WriteStartElement("Email Id");
    protected void Button2_Click(object sender, EventArgs e)

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
Updated 8-Aug-12 6:06am
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.

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
Volynsky Alex 8-Aug-12 19:05pm    
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    
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:[^].

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:[^],[^].

Share this answer
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.
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);

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 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