Newbie in XML with C# question

Hello,

I am learning how to using XML documents to store data.

I get this error:
Access to the path "c:\inetpub\wwwroot\Info.xml" is denied.

I have tried with the full path of the file, with / infront of the file.

How do I get the data in too the xml document


Here is the code below:
using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Xml;

using System.Xml.XPath;

using System.Xml.Xsl;

namespace xDoc

{

/// <summary>

/// Summary description for WebForm1.

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Label Label1;

protected System.Web.UI.WebControls.TextBox txtName;

protected System.Web.UI.WebControls.Label Label2;

protected System.Web.UI.WebControls.TextBox txtEmail;

protected System.Web.UI.WebControls.Label Label3;

protected System.Web.UI.WebControls.TextBox txtComments;

protected System.Web.UI.WebControls.Button btnSubmit;

protected System.Web.UI.WebControls.Button btnClear;

protected System.Web.UI.WebControls.Label Label4;


private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}


/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

private void btnSubmit_Click(object sender, System.EventArgs e)

{

try

{

XmlTextWriter xDoc = new XmlTextWriter(Request.MapPath("Info.xml"),

System.Text.Encoding.Default);

xDoc.Formatting = Formatting.Indented;

xDoc.WriteStartDocument();

xDoc.WriteComment("2004 eXQue");


xDoc.WriteStartElement("Comments");

xDoc.WriteStartElement("Name");

xDoc.WriteString(txtName.Text);

xDoc.WriteEndElement();

xDoc.WriteStartElement("Email");

xDoc.WriteString(txtEmail.Text);

xDoc.WriteEndElement();

xDoc.WriteStartElement("Comments");

xDoc.WriteString(txtComments.Text);

xDoc.WriteEndElement();

xDoc.WriteEndDocument();


xDoc.Close();

Label4.Text = "Done";

}

catch (Exception ex)

{

Label4.Text = ex.Message.ToString();

}

}

}

}





TIA



Aaron


0
wu_jen (2)
9/18/2004 6:34:08 AM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
609 Views

Similar Articles

[PageSpeed] 10

"Aaron" <wu_jen@hotmail.com> wrote in message news:utqZ3lUnEHA.1184@TK2MSFTNGP10.phx.gbl...
> I get this error:
> Access to the path "c:\inetpub\wwwroot\Info.xml" is denied.
: :
> XmlTextWriter xDoc = new XmlTextWriter(Request.MapPath("Info.xml"),

You need to grant the ASPNET worker process user account
privileges to read/write/modify files in the \inetpub\wwwroot
directory (this paints the solution with a bit of a broad brush,
but it's also the simplest answer).

In Windows Explorer, navigate to that directory, right-click on
it, select Properties, Security tab, etc.  Make sure that the
ASPNET user has read/write/modify rights, if not Add the
user account (if you're running Windows 2003 Server and
IIS 6.0, the user is named NetworkService).

A parting word on security -- please look into writing least-
privileged apps and use impersonation to a different user
account for your web application than the default ASPNET
account, and then set very constrained privileges on that
application user account so it can only write files off in
some application subdirectory (not wwwroot).  I know this
is probably just a learning sample app, and I offer the
simple answer alongside this caveat that determining
the proper security policy for a production app isn't as
simple.


Derek Harmon


0
loresayer (274)
9/18/2004 7:14:18 PM
Derek,
Thanks

Aaron
"Derek Harmon" <loresayer@msn.com> wrote in message
news:%23Uw0yObnEHA.3908@TK2MSFTNGP09.phx.gbl...
> "Aaron" <wu_jen@hotmail.com> wrote in message
news:utqZ3lUnEHA.1184@TK2MSFTNGP10.phx.gbl...
> > I get this error:
> > Access to the path "c:\inetpub\wwwroot\Info.xml" is denied.
> : :
> > XmlTextWriter xDoc = new XmlTextWriter(Request.MapPath("Info.xml"),
>
> You need to grant the ASPNET worker process user account
> privileges to read/write/modify files in the \inetpub\wwwroot
> directory (this paints the solution with a bit of a broad brush,
> but it's also the simplest answer).
>
> In Windows Explorer, navigate to that directory, right-click on
> it, select Properties, Security tab, etc.  Make sure that the
> ASPNET user has read/write/modify rights, if not Add the
> user account (if you're running Windows 2003 Server and
> IIS 6.0, the user is named NetworkService).
>
> A parting word on security -- please look into writing least-
> privileged apps and use impersonation to a different user
> account for your web application than the default ASPNET
> account, and then set very constrained privileges on that
> application user account so it can only write files off in
> some application subdirectory (not wwwroot).  I know this
> is probably just a learning sample app, and I offer the
> simple answer alongside this caveat that determining
> the proper security policy for a production app isn't as
> simple.
>
>
> Derek Harmon
>
>


0
wu_jen (2)
9/18/2004 10:45:29 PM
Reply:

Similar Artilces:

Please help with Excel VB question
Hi, I'm trying to set a Name range in Excel through VB, by setting the name property when a specific cell in a worksheet is changed. The code is as follows: fred1 = CStr("=PL!$A$4:$E$" Worksheets("Control").Range("maxnumpass").Value) ActiveWorkbook.Names.Add Name:="numpasslist", RefersTo:=fred1 My problem is that the change is only active for the worksheet where I change the cell. Is it possible to ensure that this change takes effect across all worksheets in the workbook? Any and all help appreciated either in a reply to this post or on jgal...

Multithreading Question
Hi, I am writing a multithreaded server application. I have written a class to handle thread(CThread , say) activities like creating, suspending, resuming threads etc. I have derived a class from CThread (CMainThread, say) and a class (CClientThread, say) to handle client connection which is also derived from CThread. In CMainThread class i am creating a thread and waiting for incomming connections. As soon as a connection came i am creating an object for CClientThread and call the function to create a thread and so on. code flow: 1. Start the main listening thread. 2. wait for a con...

MS CRM Certification question
Hi all, I have a question regarding the CRM certification? What, if any, certifications are there available with MS CRM? Is there anything like CRM Professional? Have I earned any certification if I passed the Applications Professional exam? T.I.A -- Kuba Skalbania [MCAD] ...

update trigger question
If I have something like this in an update trigger: if update(FirstName) or update(LastName) begin update n set FullName = i.FirstName + ' ' + i.LastName from Names n inner join inserted i on n.NameID = i.NameID end I only want FullName to update if either FirstName or LastName are updated. Here's my question. A batch update updates 50 rows in the table. Of the 50, only 20 have changes made to the FirstName or LastName columns. It's my understanding that the "if update()" ONLY allows 20 rows that fit the if update criteria to be updated in the...

Tired and dumb. XML & the DOM
Hi all, I've spent literally hours trying to figure this one out. I'm re-developing an app from vb6 to vb.net, and I cannot get my XML code working. I've just started using .NET. I'm tired, highly annoyed and this is my problem (I know it is very easy for someone who has done this before): My entire XML file is here - The '<CALL_12260>' tag name is dynamic (the XML file is generated by something else), everything else stays the same. I would like to easily read the contents of every node selectively: <CDC> <CALL_12260> <JobKey>65</JobKey>...

Newbie, accnts. payable & accnts.receivable sample DB
Hi guys, I�m running access 2003, windows xp pro SP2 I've been commission in my work to do a small application to track and report the accounts payable and accounts receivable movements, I'm not an accounting savvy person :(, does anyone know of a link or sample access database that can help me with the basic structure of the tables and reports?, any help would be greatly appreciated. Thanks ...

Really simple questions re CSliderCtrl
Using SetSelection() I can get a CSliderCtrl to display a highlighted selection ... but so what? What use is it other than to look pretty? Which of the following is possible, and how do I do them? (1) Prevent the user from moving the thumb outside the highlighted range. (This seems to be what the documentation suggests that SetSelection does, but in fact it doesn't, the thumb can be moved outside the selection.) (2) Have the user change the selection. (The documentation seems to suggest this is possible, but I can find no combination of keystrokes or mouse actions that will do it.) -- ...

Cannot read the XML file if there is schema
Here is the XML file: <?xml version="1.0" encoding="UTF-8" ?> - <CTMS xmlns="ctms-20.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="ctms-20.xsd http://www.clinphone.com/schema/CTMS-20.xsd" transferType="Incremental" transferId="-1" previousTransferId="-1" creationDateTime="2006-10-13T01:01:01" metaDataVersion="1.0"> - <StudyData studyId="HGS1006C1056"> - <SubjectManagement countryId="USA" siteId="US123" patId=&q...

xml form
Hi, is there a product to edit xml-Files like Excel-Files, something that provides the xml-data in a form that lets 'innocent' users easily and error-tolerantly edit the data? Thanks for help, Chris ...

Visio Newbie
Hello all, this is my first time using Visio for drawing a floor plan and I have a quick question. Yesterday, (Using a tape measure) I mapped out the floor plan of an office my company might be moving into. I wrote everything down in Inches. Is there a way once I get a room shape kinda close to teh measurements, that I can manually type in teh length for each wall? if not in inches, at least in feet. For example, I have one wall that is 154 inches ( 12.83 ft) Then the next wall is 242 incehs( 20.1 ft) The opposite wall of the first measurement is 288 inches, third wall 100 inches, then 13...

Printing question
We are having an issue with LPR printing using our software in conjucntion with a Windows 2008 server which is preventing us from being able to flash images to a printer from our application. We use Universe, SB+ and SBClient and would use the DOS shell from inside SBClient to use LPR print commands to send the images to the printer, this has worked fine on all other Windows servers but not 2008. What happens is when you drop to DOS you can browse to the %systemroot%\system32 folder and do a dir but you cannot see LPR. If you do the same from a normal command prompt the file ...

Exchange newbie problem
Hi all; A user on our domain was deleted when he should not have been. His mail box was not deleted. When his account was recreated, we tried to reconnect the old mailbox. But when selecting a user in the "Select a new user for this mailbox" dialog a message comes back saying that the user cannot be found. We tried several different users a none can be found even though they can get there mail just fine. We need to get the messages from this mailbox. Any ideas would be great -- Craig in the High Desert. craig@craignet.com But it's a dry heat. you should be able to reconnec...

C++ / Access Newbie
Hi Folks... I have a small commercial package written in C++ (targeted to Windows platforms) that uses its own proprietary database. We are just starting to investigate the option of replacing our database with a commercial package, such as Access or MySQL. Can anyone recommend informative reading that provides details on programming C++ with either of these two databases? At this stage we have no (any I mean ZERO) experience such programming. Any information would be helpful: recommendations for Access over MySQL (or vice versa), sources of such comparisons, licensing considerations, OD...

how to add or remove entity to a xml file
could someone tell me how to add or remove entity to a xml file when i dim xmlentity as new xmlentity it's say it's sube new is private thks "terry" <terry@discussions.microsoft.com> wrote in message news:DA844CFA-2EFD-4E9A-86FC-13CC909201E6@microsoft.com... > could someone tell me how to add or remove entity to a xml file XmlEntity can't be directly instantiated, you have to work through the InternalSubset of the DTD (as represented by the XmlDocumentType class). When you specify the InternalSubset for an XmlDocumentType object that you can create through a...

newbie
joining the group Hey Newbie where are you from and what versiona re you using? Fliehigh "cthomas23@hotmail.com" wrote: > joining the group > ...

Exchange 2000 Question #2
I migrated my exchange server to new hardware recently. The process I followed was to add the new server to our site, move the mailboxes, rehome public folders, and then uninstall Exchange on the old server. After I uninstalled Exchange on the old server, Active Directory still lists the old server when I create a new user and get to the Exchange mailbox portion of the create user wizard. What do I need to do to eliminate references to the old server in AD? What did I miss? Jeff You can use ADSI Edit to delete the server object. You do this drilling down through the configuration cont...

XML validating and writing at the same time
I am receiving XML data that I would like to validate against my schema and write at the same time. Some of the data is optional, if the data in the optional elements is incorrect, I would like to write blank data to that element, and then continue validating against my schema. Any ideas? -={Brian Kedersha}=- kedershab@cox.net Brian, Interesting problem. I don't think there is an easy way to do this. Did you think of a way to approach it? -- Kathleen Dollard Microsoft MVP Author "Code Generation in Microsoft .NET" "Brian Kedersha" <bkedersha@aol.com> wr...

ot question
except for being something i need to do in an mfc app i'm working on this doesn't really have anything to do with mfc.... but its as bad a place to start as any other group i watch. i need a kind of generic algorithm to take an array of 3d points that describe a surface, then given two coordinates of another point interpolate the third coordinate on the surface. picture it like you have a set of random latitude, longitude and elevation points, then want to find the elevation of any given latitude and longitude coordinate. (over a small area, don't worry about spherical earth and...

reformulating question regarding maximum value
I had an hour ago put a question up named "find maximum", but I had not formulated my query fully, hence this query. In each row, I want to find the second highest value in that row, and then as output give the value of that cell in the first row. For example: 1 2 6 8 6 5 4 3 2 4 5 6 3 2 3 8 6 4 5 3 7 2 3 1 The second largest value in the second row is nr 6. It is in the fourht cell of that row. The fourth cell of the first row is the value 8. This should be the output for the second row. The second largest value in the third row is the number 6. It is in the first cell of th...

xml serializer treatment of collection objects
If I understand the Xml Serializer correctly, as it is serializing an object graph, if it comes across a collection object, it puts a tag in for the collection and then tries to serialize all of the members of the collection. This is roughly the same treatment when the top of my object graph is itself a collection. I'm curious, however, about 2 things with regard to passing a custom collection object to the XmlSerializer: 1) Why cannot I not use the XmlRootAttribute on my collection object to specify a custom tag name for my collection? 2) What exactly does the XmlSerializer do...

Another COUNTIF question...
Hey all, i'm stuck. I need to do a formula that will count the number of cells in column 'A' only if the corresponding cell in column 'B' has a value of '0'. =COUNTIF(O:0,"0")+COUNTIF(P:P,">0") - just counts both, and that's as far as i have got. Can anyone help me please. Thanks ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ Hi =SUMPRODUCT((A1:A65536>0)*(B1:B65536<>"")*(B1:B65536=0)) (you...

Real Newbie newbie question
Hi All - I hope you can help me! I have Finepix M603 camera and although I take reasonable shots in daytime, I'm not able to produce anything at night. eg On The Thames on New Years Eve, may people were using digital cameras and their screens should clear bright picture - mine was black! What setting should I set on mine? Any advice really appreciated. --- David Scott Hampshire, England Wrong group. Sorry....... -- --- David Scott Hampshire, England "Dave" <cadasco@SUPERhotmail.com> wrote in message news:50kuejF1fh28sU1@mid.individual.net... > Hi All - I hope...

Exchange 2003 web access questions
Hi there: We've recently added an Exchange 2003 server into our network, while leaving the original Exchange 2000 server up and running with a few mailboxes on it. I'm currently having a problem completing the transition to 2003 because some old code doesn't seem to work anymore. We have implemented a very limited email interface for our factory workers, so that they can only send email to approved addresses, and all emails are CC'd to supervisors. I wrote this interface a couple of years ago in ASP, and it does every thing we need. If we try to copy this interface over to t...

eConnect newbie
Hi, I've installed eConnect 7.5 and am planning to use this to read & write xml files to GP can anyone give me samples or examples of how to do this, also my company is planning to upgrade to GP 9 shortly are there major changes between each version? Thanks in advance. JimB If you've installed eConnect, then you have several samples already. They are located in the samples folder underneath the eConnect installation. The changes from 7.5 to 9.0 are fairly minimal. Mostly, there are new xml elements that can be included, but many of those are optional. It's my gue...

MDI newbie ?
I want to add a "reload" command that will close the current(and only) document and reload it again. Here is what I have tried so far: <code> AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_FILE_NEW); while(AfxGetApp()->GetOpenDocumentCount() > 0); AfxGetApp()->OpenDocumentFile(currentFluPath); </code> This doesn't work, because, as I've learned ID_FILE_NEW create just that, a new blank document so count is still 1. I can't figure out what I should check for, how I can know when the ID_FILE_NEW is done so that I can call OpenDocumentFile() Does ...